public static void PopGlobalTable(this LuaState luaState) { if (!luaState.IsTable(-1)) { throw new Exception("expect table - " + luaState.Type(-1).ToString()); } //REG[2]=value at top? //luaState.RawSetInteger(LuaRegistry.Index, (long) LuaRegistryIndex.Globals); luaState.GetGlobal("setfenv"); if (!luaState.IsCFunction(-1)) { throw new Exception("expect setfenv"); } luaState.PushInteger(1); luaState.PushCopy(-3); try { luaState.Call(2, 0); }catch (Exception e) { Debug.WriteLine(e.Message); } }