示例#1
0
        public LuaType Type(int idx)
        {
            if (!_stack.IsValid(idx))
            {
                return(Constant.LUA_TNONE);
            }

            var val = _stack.Get(idx);

            return(LuaValue.TypeOf(val));
        }
示例#2
0
        private LuaType GetTable(object t, object k, bool raw)
        {
            if (t is LuaTable luaTable)
            {
                var v = luaTable.Get(k);
                if (raw || v != null || !luaTable.HasMetafield("__index"))
                {
                    _stack.Push(v);
                    return(LuaValue.TypeOf(v));
                }
            }

            if (raw)
            {
                throw new Exception("not a table!");
            }
            {
                var mf = GetMetafield(t, "__index", this);
                if (mf == null)
                {
                    throw new Exception("not a table!");
                }
                switch (mf)
                {
                case LuaTable mfTable:
                    GetTable(mfTable, k, false);
                    break;

                case Closure closure:
                    _stack.Push(closure);
                    _stack.Push(t);
                    _stack.Push(k);
                    Call(2, 1);
                    var v = _stack.Get(-1);
                    return(LuaValue.TypeOf(v));
                }
            }

            throw new Exception("not a table!");
        }