public T LoadString <T>(byte[] chunk, string chunkName = "chunk", LuaTable env = null) { #if THREAD_SAFE || HOTFIX_ENABLE lock (luaEnvLock) { #endif if (typeof(T) != typeof(LuaFunction) && !typeof(T).IsSubclassOf(typeof(Delegate))) { throw new InvalidOperationException(typeof(T).Name + " is not a delegate type nor LuaFunction"); } var _L = L; int oldTop = LuaAPI.lua_gettop(_L); if (LuaAPI.xluaL_loadbuffer(_L, chunk, chunk.Length, chunkName) != 0) { ThrowExceptionFromError(oldTop); } if (env != null) { env.push(_L); LuaAPI.lua_setfenv(_L, -2); } T result = (T)translator.GetObject(_L, -1, typeof(T)); LuaAPI.lua_settop(_L, oldTop); return(result); #if THREAD_SAFE || HOTFIX_ENABLE } #endif }
public static int Execute(RealStatePtr L) { if (!LuaAPI.lua_isfunction(L, 1)) { return(LuaAPI.luaL_error(L, "invalid compiled template, function needed!\r\n")); } if (LuaAPI.lua_istable(L, 2)) { LuaAPI.lua_setfenv(L, 1); } LuaAPI.lua_pcall(L, 0, 1, 0); return(1); }
public void SetEnv(LuaTable env) { #if THREAD_SAFT || HOTFIX_ENABLE lock (luaEnv.luaEnvLock) { #endif var L = luaEnv.L; int oldTop = LuaAPI.lua_gettop(L); push(L); env.push(L); LuaAPI.lua_setfenv(L, -2); LuaAPI.lua_settop(L, oldTop); #if THREAD_SAFT || HOTFIX_ENABLE } #endif }
public void SetEnv(LuaTable env) { #if THREAD_SAFT || HOTFIX_ENABLE lock (luaEnv.luaEnvLock) { #endif if (LuaIndexes.LUA_REGISTRYINDEX != -10000) { throw new InvalidOperationException("SetEnv not support in lua53"); } var L = luaEnv.L; int oldTop = LuaAPI.lua_gettop(L); push(L); env.push(L); LuaAPI.lua_setfenv(L, -2); LuaAPI.lua_settop(L, oldTop); #if THREAD_SAFT || HOTFIX_ENABLE } #endif }
public object[] DoString(string chunk, string chunkName = "chunk", LuaTable env = null) { #if THREAD_SAFT || HOTFIX_ENABLE lock (luaEnvLock) { #endif var _L = L; int oldTop = LuaAPI.lua_gettop(_L); int errFunc = LuaAPI.load_error_func(_L, errorFuncRef); if (LuaAPI.luaL_loadbuffer(_L, chunk, chunkName) == 0) { if (env != null) { env.push(_L); LuaAPI.lua_setfenv(_L, -2); } //if (LuaAPI.lua_pcall(_L, 0, -1, errFunc) == 0) if (LuaAPI.lua_pcall(_L, 0, -1, 0) == 0) { LuaAPI.lua_remove(_L, errFunc); return(translator.popValues(_L, oldTop)); } else { ThrowExceptionFromError(oldTop); } } else { ThrowExceptionFromError(oldTop); } return(null); #if THREAD_SAFT || HOTFIX_ENABLE } #endif }