public static bool InitJSEngine() { if (!JSApi.JSh_Init()) { return(false); } rt = JSApi.JSh_NewRuntime(8 * 1024 * 1024, 0); JSApi.JSh_SetNativeStackQuota(rt, 500000, 0, 0); cx = JSApi.JSh_NewContext(rt, 8192); // Set error reporter JSApi.JSh_SetErrorReporter(cx, new JSApi.JSErrorReporter(errorReporter)); glob = JSApi.JSh_NewGlobalObject(cx, 1); JSApi.JSh_EnterCompartment(cx, glob); if (!JSApi.JSh_InitStandardClasses(cx, glob)) { Debug.LogError("JSh_InitStandardClasses fail. Make sure JSh_SetNativeStackQuota was called."); return(false); } JSApi.JSh_InitReflect(cx, glob); JSApi.JSh_DefineFunction(cx, glob, "printInt", Marshal.GetFunctionPointerForDelegate(new JSApi.JSNative(printInt)), 1, 0 /*4164*/); JSApi.JSh_DefineFunction(cx, glob, "printString", Marshal.GetFunctionPointerForDelegate(new JSApi.JSNative(printString)), 1, 0 /*4164*/); JSApi.JSh_DefineFunction(cx, glob, "printDouble", Marshal.GetFunctionPointerForDelegate(new JSApi.JSNative(printDouble)), 1, 0 /*4164*/); // Resources.Load JSMgr.RegisterCS(cx, glob); JSValueWrap.Register(CSOBJ, cx); // if (useReflection) // { // for (int i = 0; i < JSBindingSettings.classes.Length; i++) // JSMgr.AddTypeInfo(JSBindingSettings.classes[i]); // } bool jsRegistered = false; /* * Uncomment these 2 lines after generating bindings!! */ //CSharpGenerated.RegisterAll(); // register cs function //jsRegistered = JSMgr.EvaluateGeneratedScripts(JSGeneratedFileNames.names); // register js functions if (!jsRegistered) { Debug.LogWarning("JS not registered!! Find me, fix me!!"); } return(jsRegistered); }