@@ -43,10 +43,37 @@ private void InitApi(int apiVersionExpect)
4343 }
4444 }
4545
46+ public static void LogCallback ( IntPtr msg )
47+ {
48+ #if PUERTS_GENERAL || ( UNITY_WSA && ! UNITY_EDITOR )
49+ System . Console . WriteLine ( MarshalExtensions . PtrToStringUTF8 ( msg ) ) ;
50+ #else
51+ UnityEngine . Debug . Log ( MarshalExtensions . PtrToStringUTF8 ( msg ) ) ;
52+ #endif
53+ }
54+
55+ public static void LogWarningCallback ( IntPtr msg )
56+ {
57+ #if PUERTS_GENERAL || ( UNITY_WSA && ! UNITY_EDITOR )
58+ #else
59+ UnityEngine . Debug . Log ( MarshalExtensions . PtrToStringUTF8 ( msg ) ) ;
60+ #endif
61+ }
62+
63+ public static void LogErrorCallback ( IntPtr msg )
64+ {
65+ #if PUERTS_GENERAL || ( UNITY_WSA && ! UNITY_EDITOR )
66+ #else
67+ UnityEngine . Debug . Log ( MarshalExtensions . PtrToStringUTF8 ( msg ) ) ;
68+ #endif
69+ }
70+
4671 public ScriptEnv ( Backend backend , int debugPort = - 1 )
4772 {
4873 this . backend = backend ;
4974
75+ // PuertsNative.SetLogCallback(LogCallback, LogWarningCallback, LogErrorCallback);
76+
5077 const int libVersionExpect = 11 ;
5178 int libVersion = PuertsNative . GetPapiVersion ( ) ;
5279 if ( libVersion != libVersionExpect )
@@ -389,7 +416,7 @@ public void Dispose()
389416 private bool disposed = false ;
390417
391418 protected virtual void Dispose ( bool dispose )
392- {
419+ {
393420#if THREAD_SAFE
394421 lock ( this ) {
395422#endif
@@ -398,12 +425,12 @@ protected virtual void Dispose(bool dispose)
398425 backend . CloseRemoteDebugger ( ) ;
399426 // quickjs void JS_FreeRuntime(JSRuntime *): assertion "list_empty(&rt->gc_obj_list)"
400427 TickHandler = null ;
401- moduleExecutor = null ;
428+ moduleExecutor = null ;
402429#if THREAD_SAFE
403430 }
404431#endif
405432 GC . Collect ( ) ;
406- GC . WaitForPendingFinalizers ( ) ;
433+ GC . WaitForPendingFinalizers ( ) ;
407434#if THREAD_SAFE
408435 lock ( this ) {
409436#endif
@@ -424,13 +451,13 @@ protected virtual void Dispose(bool dispose)
424451 PuertsNative . pesapi_close_scope ( papis , scope ) ;
425452
426453 backend . DestroyEnvRef ( envRef ) ;
427- disposed = true ;
428-
454+ disposed = true ;
455+
429456#if THREAD_SAFE
430457 lock ( scriptEnvs )
431458 {
432459#endif
433- scriptEnvs [ Idx ] = null ;
460+ scriptEnvs [ Idx ] = null ;
434461#if THREAD_SAFE
435462 }
436463 }
@@ -450,6 +477,6 @@ public bool CheckLiveness(bool shouldThrow = true)
450477}
451478
452479#endif
453-
454-
455-
480+
481+
482+
0 commit comments