lua_rawget() 개인적인 메소드

private lua_rawget ( IntPtr luaState, int index ) : void
luaState System.IntPtr
index int
리턴 void
예제 #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)
        {
            if (metatable == "luaNet_metatable")
            {
                // Gets or creates the metatable for the object's type
                LuaDLL.luaL_getmetatable(luaState, o.GetType().AssemblyQualifiedName);

                if (LuaDLL.lua_isnil(luaState, -1))
                {
                    LuaDLL.lua_settop(luaState, -2);
                    LuaDLL.luaL_newmetatable(luaState, o.GetType().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);
                    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);
            }

            // Stores the object index in the Lua list and pushes the
            // index into the Lua stack
            LuaDLL.luaL_getmetatable(luaState, "luaNet_objects");
            LuaDLL.luanet_newudata(luaState, index);
            LuaDLL.lua_pushvalue(luaState, -3);
            LuaDLL.lua_remove(luaState, -4);
            LuaDLL.lua_setmetatable(luaState, -2);
            LuaDLL.lua_pushvalue(luaState, -1);
            LuaDLL.lua_rawseti(luaState, -3, index);
            LuaDLL.lua_remove(luaState, -2);
        }
 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.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);
         }
     }
     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);
 }
        public void PushNewValueObject(IntPtr luaState, object o, int index)
        {
            LuaDLL.luanet_newudata(luaState, index);

            //string meta = GetAQName(o.GetType());
            //LuaDLL.luaL_getmetatable(luaState, meta);
            Type t = o.GetType();

            PushMetaTable(luaState, o.GetType());

            if (LuaDLL.lua_isnil(luaState, -1))
            {
                string meta = t.AssemblyQualifiedName;
#if UNITY_EDITOR
                //Debugger.LogWarning("Create not wrap ulua type:" + meta);
#endif
                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);
            }

            LuaDLL.lua_setmetatable(luaState, -2);
        }
예제 #4
0
        void CreateMetaTable(IntPtr luaState, object o, string metatable)
        {
            if (metatable == "luaNet_metatable")
            {
                // Gets or creates the metatable for the object's type
                LuaDLL.luaL_getmetatable(luaState, o.GetType().AssemblyQualifiedName);

                if (LuaDLL.lua_isnil(luaState, -1))
                {
                    LuaDLL.lua_settop(luaState, -2);
                    LuaDLL.luaL_newmetatable(luaState, o.GetType().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);
                    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);
            }
        }
예제 #5
0
 public static void lua_rawglobal(IntPtr luaState, string name)
 {
     LuaDLL.lua_pushstring(luaState, name);
     LuaDLL.lua_rawget(luaState, LuaIndexes.LUA_GLOBALSINDEX);
 }
예제 #6
0
 public void LuaRawGlobal(string name)
 {
     LuaDLL.lua_pushstring(L, name);
     LuaDLL.lua_rawget(L, LuaIndexes.LUA_GLOBALSINDEX);
 }
예제 #7
0
 public void LuaRawGet(int idx)
 {
     LuaDLL.lua_rawget(L, idx);
 }
예제 #8
0
        //L:  [namespace Table]
        public bool AddObject(IntPtr L, System.Object obj, string metatable /* nullable */)
        {
            IntPtr userdata = IntPtr.Zero;

            if (luaObjs.TryGetValue(obj, out userdata))
            {
                LuaDLL.lua_rawgeti(L, LuaDLL.LUA_REGISTRYINDEX, weakRefForUserData); //namespace,reftable
                LuaDLL.lua_pushlightuserdata(L, userdata);                           //namespace,reftable,userdataKey
                LuaDLL.lua_rawget(L, -2);                                            //namespace,reftable,userdata
                LuaDLL.lua_remove(L, -2);                                            //namespace,userdata
                if (LuaDLL.lua_isuserdata(L, -1))
                {
                    return(true);
                }
                else
                {
                    LuaDLL.lua_pop(L, 1);                     //namespace
                }
            }

            userdata = LuaDLL.lua_newuserdata(L, 1);             //namespace,obj

            if (metatable == null)
            {
                Type type = obj.GetType();
                while (type != null)
                {
                    LuaDLL.wlua_getfield(L, -2, type.Name);                    //namespace,obj,typet
                    if (LuaDLL.lua_isnil(L, -1))
                    {
                        LuaDLL.lua_pop(L, 1);                         //namespace,obj
                        type = type.BaseType;
                        continue;
                    }
                    if (LuaDLL.lua_istable(L, -1))
                    {
                        metatable = type.Name;
                        break;
                    }
                    else
                    {
                        LuaDLL.lua_pop(L, 2);                         //namespace
                        throw new LuaException(L, "metatable must be a table:" + type.Name);
                    }
                }
            }
            else
            {
                LuaDLL.wlua_getfield(L, -2, metatable);                //namespace,obj,typet
                if (LuaDLL.lua_isnil(L, -1))
                {
                    LuaDLL.lua_pop(L, 2);                     //namespace
                    throw new LuaException(L, "failed to find metatable:" + metatable);
                }
            }

            //namespace,obj,typet
            LuaDLL.lua_setmetatable(L, -2);             //namespace,obj
            objs[userdata.ToInt64()] = obj;
            luaObjs[obj]             = userdata;

            LuaDLL.lua_rawgeti(L, LuaDLL.LUA_REGISTRYINDEX, weakRefForUserData); //namespace,obj,reftable
            LuaDLL.lua_pushlightuserdata(L, userdata);                           //namespace,obj,reftable,userdatakey
            LuaDLL.lua_pushvalue(L, -3);                                         //namespace,obj,reftable,userdatakey,obj
            LuaDLL.lua_rawset(L, -3);                                            //namespace,obj,reftable
            LuaDLL.lua_pop(L, 1);                                                //namespace,obj

            return(true);
        }