Exemple #1
0
        private int UnregisterTableInternal(LuaState luaState)
        {
            if (!luaState.GetMetaTable(1))
            {
                ThrowError(luaState, "unregister_table: arg is not valid table");
                return(0);
            }

            luaState.PushString("__index");
            luaState.GetTable(-2);
            object obj = GetRawNetObject(luaState, -1);

            if (obj == null)
            {
                ThrowError(luaState, "unregister_table: arg is not valid table");
            }

            var luaTableField = obj.GetType().GetField("__luaInterface_luaTable");

            if (luaTableField == null)
            {
                ThrowError(luaState, "unregister_table: arg is not valid table");
            }

            // ReSharper disable once PossibleNullReferenceException
            luaTableField.SetValue(obj, null);
            luaState.PushNil();
            luaState.SetMetaTable(1);
            luaState.PushString("base");
            luaState.PushNil();
            luaState.SetTable(1);

            return(0);
        }
Exemple #2
0
        /*
         * Navigates a table in the top of the stack, returning
         * the value of the specified field
         */
        object GetObject(string[] remainingPath)
        {
            object returnValue = null;

            for (int i = 0; i < remainingPath.Length; i++)
            {
                luaState.PushString(remainingPath[i]);
                luaState.GetTable(-2);
                returnValue = translator.GetObject(luaState, -1);

                if (returnValue == null)
                {
                    break;
                }
            }

            return(returnValue);
        }
Exemple #3
0
        /*
         * Navigates a table in the top of the stack, returning
         * the value of the specified field
         */
        object GetObject(string[] remainingPath)
        {
            object returnValue = null;

            for (int i = 0; i < remainingPath.Length; i++)
            {
                _luaState.PushString(remainingPath[i]);
                _luaState.GetTable(-2);
                var oldValue = returnValue;
                returnValue = _translator.GetObject(_luaState, -1);
                (oldValue as LuaBase)?.Dispose();

                if (returnValue == null)
                {
                    break;
                }
            }

            return(returnValue);
        }
Exemple #4
0
        /*
         * CAUTION: NLua.Lua instances can't share the same lua state!
         */
        public Lua(LuaState luaState)
        {
            luaState.PushString("NLua_Loaded");
            luaState.GetTable((int)LuaRegistry.Index);

            if (luaState.ToBoolean(-1))
            {
                luaState.SetTop(-2);
                throw new LuaException("There is already a NLua.Lua instance associated with this Lua state");
            }

            _luaState    = luaState;
            _StatePassed = true;
            luaState.SetTop(-2);
            Init();
        }
Exemple #5
0
        private int UnregisterTableInternal(LuaState luaState)
        {
            try
            {
                if (luaState.GetMetaTable(1))
                {
                    luaState.PushString("__index");
                    luaState.GetTable(-2);
                    object obj = GetRawNetObject(luaState, -1);

                    if (obj == null)
                    {
                        ThrowError(luaState, "unregister_table: arg is not valid table");
                    }

                    var luaTableField = obj.GetType().GetField("__luaInterface_luaTable");

                    if (luaTableField == null)
                    {
                        ThrowError(luaState, "unregister_table: arg is not valid table");
                    }

                    luaTableField.SetValue(obj, null);
                    luaState.PushNil();
                    luaState.SetMetaTable(1);
                    luaState.PushString("base");
                    luaState.PushNil();
                    luaState.SetTable(1);
                }
                else
                {
                    ThrowError(luaState, "unregister_table: arg is not valid table");
                }
            }
            catch (Exception e)
            {
                ThrowError(luaState, e.Message);
            }

            return(0);
        }