Exemplo n.º 1
0
 public void OnLoaded(DuktapeVM vm)
 {
     tests();
     vm.AddSearchPath("Assets/Duktape/Examples/Scripts/out");
     do
     {
         if (experimentalDebugger)
         {
             // DuktapeDLL.duk_example_attach_debugger(vm.context.rawValue);
             DuktapeDebugger.CreateDebugger(vm);
             if (waitForDebuggerClient)
             {
                 Debug.Log("wait for debugger connection");
                 DuktapeDebugger.onAttached = () =>
                 {
                     DuktapeDebugger.onAttached = null;
                     RunScript(vm);
                 };
                 break;
             }
         }
         RunScript(vm);
     } while (false);
     // vm.EvalFile("test.js");
     _loaded = true;
 }
Exemplo n.º 2
0
 public void OnBinded(DuktapeVM vm, int numRegs)
 {
     if (numRegs == 0)
     {
         throw new Exception("no type binding registered, please run <MENU>/Duktape/Generate Bindings in Unity Editor Mode before the first running of this project.");
     }
 }
Exemplo n.º 3
0
 void Awake()
 {
     vm = new DuktapeVM(null, 1024 * 1024 * 4);
     // vm = new DuktapeVM();
     // vm.Initialize(new RFileSystem(), this);
     vm.Initialize(this);
 }
Exemplo n.º 4
0
 private void RunScript(DuktapeVM vm)
 {
     if (jsBytecode)
     {
         var fr       = vm.fileResolver;
         var bytecode = fr.ReadAllBytes(launchScript + ".bytes");
         if (bytecode != null)
         {
             vm.EvalMain(launchScript, bytecode);
         }
         else
         {
             var source = fr.ReadAllBytes(launchScript);
             bytecode = vm.DumpBytecode(launchScript, source);
             Debug.LogFormat("{0} => {1} (bytecode)", source.Length, bytecode.Length);
             System.IO.File.WriteAllBytes("Assets/Duktape/Examples/Scripts/out/" + launchScript + ".bytes", bytecode);
             vm.EvalMain(launchScript, bytecode);
         }
     }
     else
     {
         var f = vm.EvalSource("eval", System.Text.Encoding.UTF8.GetBytes("function x() { console.log('hello, eval.'); };x")) as DuktapeFunction;
         if (f != null)
         {
             var a = f.ToDelegate <Action>();
             a?.Invoke();
         }
         vm.EvalMain(launchScript);
     }
 }
Exemplo n.º 5
0
 void OnDestroy()
 {
     // DuktapeDebugger.Shutdown();
     if (vm.context != null)
     {
         DuktapeDLL.duk_example_detach_debugger(vm.context.rawValue, IntPtr.Zero);
     }
     vm.Destroy();
     vm = null;
 }
Exemplo n.º 6
0
 public void OnLoaded(DuktapeVM vm)
 {
     tests();
     vm.AddSearchPath("Assets/Examples/Scripts/out");
     if (experimentalDebugger)
     {
         DuktapeDLL.duk_example_attach_debugger(vm.context.rawValue);
     }
     // vm.EvalFile("test.js");
     vm.EvalMain(launchScript);
     _loaded = true;
 }
Exemplo n.º 7
0
 private void RunScript(DuktapeVM vm)
 {
     if (jsBytecode)
     {
         var fr       = vm.fileResolver;
         var bytecode = fr.ReadAllBytes(launchScript + ".bytes");
         if (bytecode != null)
         {
             vm.EvalMain(launchScript, bytecode);
         }
         else
         {
             var source = fr.ReadAllBytes(launchScript);
             bytecode = vm.DumpBytecode(launchScript, source);
             Debug.LogFormat("{0} => {1} (bytecode)", source.Length, bytecode.Length);
             System.IO.File.WriteAllBytes("Assets/Duktape/Examples/Scripts/out/" + launchScript + ".bytes", bytecode);
             vm.EvalMain(launchScript, bytecode);
         }
     }
     else
     {
         vm.EvalMain(launchScript);
     }
 }
Exemplo n.º 8
0
 public void OnProgress(DuktapeVM vm, int step, int total)
 {
 }
Exemplo n.º 9
0
 public void OnBindingError(DuktapeVM vm, Type type)
 {
 }
Exemplo n.º 10
0
 public void OnTypesBinding(DuktapeVM vm)
 {
     // 此处进行手工导入
     // var ctx = vm.context.rawValue;
     // xxx.reg(ctx);
 }
Exemplo n.º 11
0
    // void Update()
    // {
    //     Debug.LogFormat("Update");
    // }

    // void OnApplicationQuit()
    // {
    //     Debug.LogFormat("OnApplicationQuit");
    // }

    void OnDestroy()
    {
        vm.Destroy();
        vm = null;
    }