public void PushNewValueObject(IntPtr luaState, object o, int index)
        {
            LuaDLL.luanet_newudata(luaState, index);
            Type type = o.GetType();

            ObjectTranslator.PushMetaTable(luaState, o.GetType());
            if (LuaDLL.lua_isnil(luaState, -1))
            {
                string assemblyQualifiedName = type.AssemblyQualifiedName;
                Debugger.Log("<color=green>Create not wrap ulua type:" + assemblyQualifiedName + "</color>", new object[0]);
                LuaDLL.lua_settop(luaState, -2);
                LuaDLL.luaL_newmetatable(luaState, assemblyQualifiedName);
                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.0);
                LuaDLL.lua_rawset(luaState, -3);
                LuaDLL.lua_pushstring(luaState, "__index");
                LuaDLL.lua_pushstring(luaState, "luaNet_indexfunction");
                LuaDLL.lua_rawget(luaState, LuaIndexes.LUA_REGISTRYINDEX);
                LuaDLL.lua_rawset(luaState, -3);
                LuaDLL.lua_pushstring(luaState, "__gc");
                LuaDLL.lua_pushstdcallcfunction(luaState, this.metaFunctions.gcFunction, 0);
                LuaDLL.lua_rawset(luaState, -3);
                LuaDLL.lua_pushstring(luaState, "__tostring");
                LuaDLL.lua_pushstdcallcfunction(luaState, this.metaFunctions.toStringFunction, 0);
                LuaDLL.lua_rawset(luaState, -3);
                LuaDLL.lua_pushstring(luaState, "__newindex");
                LuaDLL.lua_pushstdcallcfunction(luaState, this.metaFunctions.newindexFunction, 0);
                LuaDLL.lua_rawset(luaState, -3);
            }
            LuaDLL.lua_setmetatable(luaState, -2);
        }
Example #2
0
 private void pushNewObject(IntPtr luaState, object o, int index, string metatable)
 {
     LuaDLL.lua_getref(luaState, this.weakTableRef);
     LuaDLL.luanet_newudata(luaState, index);
     if (metatable == "luaNet_metatable")
     {
         Type type = o.GetType();
         ObjectTranslator.PushMetaTable(luaState, o.GetType());
         if (LuaDLL.lua_isnil(luaState, -1))
         {
             string assemblyQualifiedName = type.AssemblyQualifiedName;
             Debugger.LogWarning("Create not wrap ulua type:" + assemblyQualifiedName, new object[0]);
             LuaDLL.lua_settop(luaState, -2);
             LuaDLL.luaL_newmetatable(luaState, assemblyQualifiedName);
             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.0);
             LuaDLL.lua_rawset(luaState, -3);
             LuaDLL.lua_pushstring(luaState, "__index");
             LuaDLL.lua_pushstring(luaState, "luaNet_indexfunction");
             LuaDLL.lua_rawget(luaState, LuaIndexes.LUA_REGISTRYINDEX);
             LuaDLL.lua_rawset(luaState, -3);
             LuaDLL.lua_pushstring(luaState, "__gc");
             LuaDLL.lua_pushstdcallcfunction(luaState, this.metaFunctions.gcFunction, 0);
             LuaDLL.lua_rawset(luaState, -3);
             LuaDLL.lua_pushstring(luaState, "__tostring");
             LuaDLL.lua_pushstdcallcfunction(luaState, this.metaFunctions.toStringFunction, 0);
             LuaDLL.lua_rawset(luaState, -3);
             LuaDLL.lua_pushstring(luaState, "__newindex");
             LuaDLL.lua_pushstdcallcfunction(luaState, this.metaFunctions.newindexFunction, 0);
             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);
 }