Beispiel #1
0
        public void Remove(ScriptState luaState, int index)
        {
            if (_cache.ContainsKey(index))
            {
                var o = _cache[index];
                _mappings.Remove(o);
                _cache.Remove(index);

                var disposer = o as IDisposable;
                if (disposer != null)
                {
                    disposer.Dispose();
                }

                // remove dotNet_objects value
                LuaCore.GetMetatable(luaState, DotNetObjectsMetatable.GlobalName);
                LuaCore.PushNull(luaState);
                LuaCore.RawSetIndex(luaState, -2, index);
            }
        }
Beispiel #2
0
        public int PushObjectEx(ScriptState luaState, object o, string metatableName)
        {
            int index;

            if (TryGetObject(luaState, o, out index))
            {
                return(index);
            }
            var uindex = AddObject(o);

            LuaCore.GetMetatable(luaState, metatableName);
            LuaCore.GetMetatable(luaState, DotNetObjectsMetatable.GlobalName);
            LuaCore.NewUserData(luaState, uindex);
            LuaCore.PushValue(luaState, -3);
            LuaCore.RemoveValue(luaState, -4);
            LuaCore.SetMetatable(luaState, -2);
            LuaCore.PushValue(luaState, -1);
            LuaCore.RawSetIndex(luaState, -3, uindex);
            LuaCore.RemoveValue(luaState, -2);
            return(uindex);
        }