public static void OpenLib(RealStatePtr L) { LuaAPI.lua_newtable(L); LuaAPI.xlua_pushasciistring(L, "compile"); LuaAPI.lua_pushstdcallcfunction(L, templateCompileFunction); LuaAPI.lua_rawset(L, -3); LuaAPI.xlua_pushasciistring(L, "execute"); LuaAPI.lua_pushstdcallcfunction(L, templateExecuteFunction); LuaAPI.lua_rawset(L, -3); LuaAPI.lua_setglobal(L, "template"); }
public LuaEnv() { #if THREAD_SAFT || HOTFIX_ENABLE lock (luaEnvLock) { #endif LuaIndexes.LUA_REGISTRYINDEX = LuaAPI.xlua_get_registry_index();; // Create State L = LuaAPI.luaL_newstate(); //Init Base Libs LuaAPI.luaopen_xlua(L); LuaAPI.luaopen_i64lib(L); LuaAPI.luaopen_perflib(L); translator = new ObjectTranslator(this, L); translator.createFunctionMetatable(L); translator.OpenLib(L); ObjectTranslatorPool.Instance.Add(L, translator); LuaAPI.lua_atpanic(L, StaticLuaCallbacks.Panic); LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.Print); LuaAPI.lua_setglobal(L, "print"); //template engine lib register TemplateEngine.LuaTemplate.OpenLib(L); AddSearcher(StaticLuaCallbacks.LoadBuiltinLib, 2); // just after the preload searcher AddSearcher(StaticLuaCallbacks.LoadFromCustomLoaders, 3); AddSearcher(StaticLuaCallbacks.LoadFromResource, 4); AddSearcher(StaticLuaCallbacks.LoadFromStreamingAssetsPath, -1); DoString(init_xlua, "Init"); init_xlua = null; AddBuildin("socket.core", StaticLuaCallbacks.LoadSocketCore); AddBuildin("socket", StaticLuaCallbacks.LoadSocketCore); LuaAPI.lua_newtable(L); //metatable of indexs and newindexs functions LuaAPI.xlua_pushasciistring(L, "__index"); LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.MetaFuncIndex); LuaAPI.lua_rawset(L, -3); LuaAPI.xlua_pushasciistring(L, Utils.LuaIndexsFieldName); LuaAPI.lua_newtable(L); LuaAPI.lua_pushvalue(L, -3); LuaAPI.lua_setmetatable(L, -2); LuaAPI.lua_rawset(L, LuaIndexes.LUA_REGISTRYINDEX); LuaAPI.xlua_pushasciistring(L, Utils.LuaNewIndexsFieldName); LuaAPI.lua_newtable(L); LuaAPI.lua_pushvalue(L, -3); LuaAPI.lua_setmetatable(L, -2); LuaAPI.lua_rawset(L, LuaIndexes.LUA_REGISTRYINDEX); LuaAPI.xlua_pushasciistring(L, Utils.LuaClassIndexsFieldName); LuaAPI.lua_newtable(L); LuaAPI.lua_pushvalue(L, -3); LuaAPI.lua_setmetatable(L, -2); LuaAPI.lua_rawset(L, LuaIndexes.LUA_REGISTRYINDEX); LuaAPI.xlua_pushasciistring(L, Utils.LuaClassNewIndexsFieldName); LuaAPI.lua_newtable(L); LuaAPI.lua_pushvalue(L, -3); LuaAPI.lua_setmetatable(L, -2); LuaAPI.lua_rawset(L, LuaIndexes.LUA_REGISTRYINDEX); LuaAPI.lua_pop(L, 1); // pop metatable of indexs and newindexs functions LuaAPI.xlua_pushasciistring(L, "xlua_main_thread"); LuaAPI.lua_pushthread(L); LuaAPI.lua_rawset(L, LuaIndexes.LUA_REGISTRYINDEX); translator.Alias(typeof(Type), "System.MonoType"); LuaAPI.lua_getglobal(L, "_G"); translator.Get(L, -1, out _G); LuaAPI.lua_pop(L, 1); errorFuncRef = LuaAPI.get_error_func_ref(L); if (initers != null) { for (int i = 0; i < initers.Count; i++) { initers[i](this, translator); } } translator.CreateArrayMetatable(L); translator.CreateDelegateMetatable(L); #if THREAD_SAFT || HOTFIX_ENABLE } #endif }