lua_getmetatable() private method

private lua_getmetatable ( IntPtr luaState, int objIndex ) : int
luaState System.IntPtr
objIndex int
return int
示例#1
0
        //把一个table func 放在栈顶
        public bool RawGetField(string field)
        {
            IntPtr   L    = _Interpreter.L;
            LuaTypes type = LuaTypes.LUA_TNONE;

            LuaDLL.lua_getref(L, _Reference);
            LuaDLL.lua_pushstring(L, field);
            LuaDLL.lua_rawget(L, -2);

            if (LuaDLL.lua_isnil(L, -1))
            {
                LuaDLL.lua_pop(L, 1);

                if (LuaDLL.lua_getmetatable(L, -1) > 0)
                {
                    LuaDLL.lua_pushstring(L, field);
                    LuaDLL.lua_rawget(L, -2);
                }
            }

            type = LuaDLL.lua_type(L, -1);

            if (type == LuaTypes.LUA_TFUNCTION)
            {
                return(true);
            }

            return(false);
        }
 public static int unregisterTable(IntPtr luaState)
 {
     ObjectTranslator translator = ObjectTranslator.FromState(luaState);
     try
     {
         if (LuaDLL.lua_getmetatable(luaState, 1) != 0)
         {
             LuaDLL.lua_pushstring(luaState, "__index");
             LuaDLL.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);
             LuaDLL.lua_pushnil(luaState);
             LuaDLL.lua_setmetatable(luaState, 1);
             LuaDLL.lua_pushstring(luaState, "base");
             LuaDLL.lua_pushnil(luaState);
             LuaDLL.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;
 }
示例#3
0
        public static IntPtr luaL_checkudata(IntPtr L, int ud, string tname)
        {
            IntPtr intPtr = LuaDLL.lua_touserdata(L, ud);

            if (intPtr != IntPtr.Zero && LuaDLL.lua_getmetatable(L, ud) != 0)
            {
                LuaDLL.lua_getfield(L, LuaIndexes.LUA_REGISTRYINDEX, tname);
                if (LuaDLL.lua_rawequal(L, -1, -2) != 0)
                {
                    LuaDLL.lua_pop(L, 2);
                    return(intPtr);
                }
            }
            LuaDLL.luaL_typerror(L, ud, tname, null);
            return(IntPtr.Zero);
        }
        public static int unregisterTable(IntPtr luaState)
        {
            ObjectTranslator objectTranslator = ObjectTranslator.FromState(luaState);

            try
            {
                if (LuaDLL.lua_getmetatable(luaState, 1) != 0)
                {
                    LuaDLL.lua_pushstring(luaState, "__index");
                    LuaDLL.lua_gettable(luaState, -2);
                    object rawNetObject = objectTranslator.getRawNetObject(luaState, -1);
                    if (rawNetObject == null)
                    {
                        objectTranslator.throwError(luaState, "unregister_table: arg is not valid table");
                    }
                    FieldInfo field = rawNetObject.GetType().GetField("__luaInterface_luaTable");
                    if (field == null)
                    {
                        objectTranslator.throwError(luaState, "unregister_table: arg is not valid table");
                    }
                    field.SetValue(rawNetObject, null);
                    LuaDLL.lua_pushnil(luaState);
                    LuaDLL.lua_setmetatable(luaState, 1);
                    LuaDLL.lua_pushstring(luaState, "base");
                    LuaDLL.lua_pushnil(luaState);
                    LuaDLL.lua_settable(luaState, 1);
                }
                else
                {
                    objectTranslator.throwError(luaState, "unregister_table: arg is not valid table");
                }
            }
            catch (Exception ex)
            {
                objectTranslator.throwError(luaState, ex.Message);
            }
            return(0);
        }
示例#5
0
 /*
  * Implementation of free_object. Clears the metatable and the
  * base field, freeing the created object for garbage-collection
  */
 private int unregisterTable(IntPtr luaState)
 {
     try
     {
         if (LuaDLL.lua_getmetatable(luaState, 1) != 0)
         {
             LuaDLL.lua_pushstring(luaState, "__index");
             LuaDLL.lua_gettable(luaState, -2);
             object obj = getRawNetObject(luaState, -1);
             if (obj == null)
             {
                 throwError(luaState, "unregister_table: arg is not valid table");
             }
             FieldInfo luaTableField = obj.GetType().GetField("__luaInterface_luaTable");
             if (luaTableField == null)
             {
                 throwError(luaState, "unregister_table: arg is not valid table");
             }
             luaTableField.SetValue(obj, null);
             LuaDLL.lua_pushnil(luaState);
             LuaDLL.lua_setmetatable(luaState, 1);
             LuaDLL.lua_pushstring(luaState, "base");
             LuaDLL.lua_pushnil(luaState);
             LuaDLL.lua_settable(luaState, 1);
         }
         else
         {
             throwError(luaState, "unregister_table: arg is not valid table");
         }
     }
     catch (Exception e)
     {
         throwError(luaState, e.Message);
     }
     return(0);
 }
示例#6
0
 public int LuaGetMetaTable(int idx)
 {
     return(LuaDLL.lua_getmetatable(L, idx));
 }
示例#7
0
文件: LuaDLL.cs 项目: sakyaer/emoji
 public static bool lua_metatableequal(IntPtr luaState, int index, string metatable)
 {
     LuaDLL.lua_getmetatable(luaState, index);
     LuaDLL.lua_getglobal(luaState, metatable);
     return(LuaDLL.lua_equal(luaState, -1, -2) > 0 ? true : false);
 }