Exemple #1
0
        public LuaBindMetatable(LuaState luaState, Type type, LuaBindMetatableType metatableType) : base(luaState)
        {
            _luaState      = luaState;
            _type          = type;
            _metatableType = metatableType;

            IntPtr L = luaState.L;

            if (luaState.Bindings.MetatableIndexMetamethod == null)
            {
                LuaLib.luaL_dostring(L, _INDEX_META_METHOD_CODE);                                                               // |f
                luaState.Bindings.MetatableIndexMetamethod = new LuaFunction(luaState, -1);
                LuaLib.lua_pop(L, 1);                                                                                           // |
                LuaLib.luaL_dostring(L, _NEWINDEX_META_METHOD_CODE);                                                            // |f
                luaState.Bindings.MetatableNewIndexMetamethod = new LuaFunction(luaState, -1);
                LuaLib.lua_pop(L, 1);                                                                                           // |
            }
            if (_gcMetamethod == null)
            {
                _gcMetamethod = new LuaCSFunction(_GC);
                _getBaseMetatableMetamethod = new LuaCSFunction(_GetBaseMetatable);
                _getMemberMetamethod        = new LuaCSFunction(_GetMember);
            }

            Push();                                                                                     // |mt

            LuaLib.lua_pushstring(L, "__refId");                                                        // |mt|s
            LuaLib.lua_pushinteger(L, _RefId);                                                          // |mt|s|v
            LuaLib.lua_rawset(L, -3);                                                                   // |mt		// mt.__refId = _RefId

            LuaLib.lua_pushstring(L, "__index");                                                        // |mt|s
            luaState.Bindings.MetatableIndexMetamethod.Push();                                          // |mt|s|v
            LuaLib.lua_rawset(L, -3);                                                                   // |mt		// mt.__index = f

            if (!type.IsEnum)
            {
                LuaLib.lua_pushstring(L, "__newindex");                                         // |mt|s
                luaState.Bindings.MetatableNewIndexMetamethod.Push();                           // |mt|s|v
                LuaLib.lua_rawset(L, -3);                                                       // |mt		// mt.__newindex = f
            }

            LuaLib.lua_pushstring(L, "__gc");                                           // |mt|s
            LuaLib.lua_pushcsfunction(L, _gcMetamethod);                                // |mt|s|csf
            LuaLib.lua_rawset(L, -3);                                                   // |mt		// mt.__gc = csf

            LuaLib.lua_pushstring(L, "__getbase");                                      // |mt|s
            LuaLib.lua_pushcsfunction(L, _getBaseMetatableMetamethod);                  // |mt|s|csf
            LuaLib.lua_rawset(L, -3);                                                   // |mt		// mt.__getbase = csf

            LuaLib.lua_pushstring(L, "__getmember");                                    // |mt|s
            LuaLib.lua_pushcsfunction(L, _getMemberMetamethod);                         // |mt|s|csf
            LuaLib.lua_rawset(L, -3);                                                   // |mt		// mt.__getmember = csf

            LuaLib.lua_pop(L, 1);                                                       // |

            luaState.Bindings.RegisterMetatableRefId(_RefId, this);
        }
Exemple #2
0
 public void PushObject(ushort o)
 {
     LuaLib.lua_pushinteger(L, o);
 }