Exemple #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);
            }
        }
Exemple #2
0
        private bool TryGetObject(ScriptState luaState, object o, out int index)
        {
            bool found = _mappings.TryGetValue(o, out index);

            if (found)
            {
                LuaCore.GetMetatable(luaState, DotNetObjectsMetatable.GlobalName);
                LuaCore.RawGetIndex(luaState, -1, index);
                var type = LuaCore.GetType(luaState, -1);
                if (type != ScriptTypes.Nil)
                {
                    LuaCore.RemoveValue(luaState, -2);
                    return(true);
                }
                LuaCore.RemoveValue(luaState, -1);
                LuaCore.RemoveValue(luaState, -1);
                Remove(luaState, index);
            }
            return(false);
        }
Exemple #3
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);
        }