Ejemplo n.º 1
0
        public static int unregisterTable(IntPtr luaState)
        {
            ObjectTranslator translator = ObjectTranslator.FromState(luaState);

            try
            {
                if (LuaAPI.lua_getmetatable(luaState, 1) != 0)
                {
                    LuaAPI.lua_pushstring(luaState, "__index");
                    LuaAPI.lua_gettable(luaState, -2);
                    object obj = translator.getRawNetObject(luaState, -1);
                    if (obj == null)
                    {
                        translator.throwError(luaState, "unregister_table: arg is not valid table");
                    }
                    FieldInfo luaTableField = obj.GetType().GetField("__luaInterface_luaTable");
                    if (luaTableField == null)
                    {
                        translator.throwError(luaState, "unregister_table: arg is not valid table");
                    }
                    luaTableField.SetValue(obj, null);
                    LuaAPI.lua_pushnil(luaState);
                    LuaAPI.lua_setmetatable(luaState, 1);
                    LuaAPI.lua_pushstring(luaState, "base");
                    LuaAPI.lua_pushnil(luaState);
                    LuaAPI.lua_settable(luaState, 1);
                }
                else
                {
                    translator.throwError(luaState, "unregister_table: arg is not valid table");
                }
            }
            catch (Exception e)
            {
                translator.throwError(luaState, e.Message);
            }
            return(0);
        }