LuaInterface.LuaDLL.luaL_newmetatable C# (CSharp) Method

luaL_newmetatable() private method

private luaL_newmetatable ( IntPtr luaState, string meta ) : int
luaState System.IntPtr
meta string
return int
        public static extern int luaL_newmetatable(IntPtr luaState, string meta);
        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]

Usage Example

示例#1
0
        /*
         * Pushes a new object into the Lua stack with the provided
         * metatable
         */
        private void pushNewObject(IntPtr luaState, object o, int index, string metatable)
        {
            //LuaDLL.luaL_getmetatable(luaState, "luaNet_objects");
            LuaDLL.lua_getref(luaState, weakTableRef);
            LuaDLL.luanet_newudata(luaState, index);

            if (metatable == "luaNet_metatable")
            {
                // Gets or creates the metatable for the object's type
                //string meta = t.AssemblyQualifiedName
                //LuaDLL.luaL_getmetatable(luaState, meta);
                Type t = o.GetType();
                PushMetaTable(luaState, o.GetType());

                if (LuaDLL.lua_isnil(luaState, -1))
                {
                    string meta = t.AssemblyQualifiedName;
                    UnityEngine.Debug.LogWarning("Create not wrap ulua type:" + meta);
                    LuaDLL.lua_settop(luaState, -2);
                    LuaDLL.luaL_newmetatable(luaState, meta);
                    LuaDLL.lua_pushstring(luaState, "cache");
                    LuaDLL.lua_newtable(luaState);
                    LuaDLL.lua_rawset(luaState, -3);
                    LuaDLL.lua_pushlightuserdata(luaState, LuaDLL.luanet_gettag());
                    LuaDLL.lua_pushnumber(luaState, 1);
                    LuaDLL.lua_rawset(luaState, -3);
                    LuaDLL.lua_pushstring(luaState, "__index");
                    LuaDLL.lua_pushstring(luaState, "luaNet_indexfunction");
                    LuaDLL.lua_rawget(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX);
                    LuaDLL.lua_rawset(luaState, -3);
                    LuaDLL.lua_pushstring(luaState, "__gc");
                    LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction);
                    LuaDLL.lua_rawset(luaState, -3);
                    LuaDLL.lua_pushstring(luaState, "__tostring");
                    LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction);
                    LuaDLL.lua_rawset(luaState, -3);
                    LuaDLL.lua_pushstring(luaState, "__newindex");
                    LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.newindexFunction);
                    LuaDLL.lua_rawset(luaState, -3);
                }
            }
            else
            {
                LuaDLL.luaL_getmetatable(luaState, metatable);
            }

            LuaDLL.lua_setmetatable(luaState, -2);
            LuaDLL.lua_pushvalue(luaState, -1);
            LuaDLL.lua_rawseti(luaState, -3, index);
            LuaDLL.lua_remove(luaState, -2);
        }
All Usage Examples Of LuaInterface.LuaDLL::luaL_newmetatable
LuaDLL