Пример #1
0
        /// <summary><see cref="RawGet(int)"/> alternative that only fetches plain Lua value types and strings.</summary>
        public LuaValue RawGetValue(int field)
        {
            var L = Owner._L;

            luaclr.checkstack(L, 2, "LuaTable.RawGetValue"); StackAssert.Start(L);
            push(L);
            lua.rawgeti(L, -1, field);
            var obj = LuaValue.read(L, -1, false);

            lua.pop(L, 2);                                    StackAssert.End();
            return(obj);
        }
Пример #2
0
        /// <summary>Gets a numeric field of a table ignoring its metatable, if it exists</summary>
        public object RawGet(int field)
        {
            var L = Owner._L;

            luaclr.checkstack(L, 2, "LuaTable.RawGet"); StackAssert.Start(L);
            push(L);
            lua.rawgeti(L, -1, field);
            var obj = Owner.translator.getObject(L, -1);

            lua.pop(L, 2);                               StackAssert.End();
            return(obj);
        }
Пример #3
0
        /// <summary>Looks up the field, ignoring metatables, and gets its Lua type.</summary>
        public LuaType RawFieldType(object field)
        {
            var L = Owner._L;

            luanet.checkstack(L, 2, "LuaTable.RawFieldType"); StackAssert.Start(L);
            push(L);
            Owner.translator.push(L, field);
            lua.rawget(L, -2);
            var type = lua.type(L, -1);

            lua.pop(L, 2);                                     StackAssert.End();
            return((LuaType)type);
        }
Пример #4
0
        /// <summary>Looks up the field and gets its Lua type. The field's value is discarded without performing any Lua to CLR translation.</summary>
        public LuaType FieldType(object field)
        {
            var L = Owner._L;

            luaclr.checkstack(L, 2, "LuaBase.FieldType"); StackAssert.Start(L);
            push(L);
            Owner.translator.push(L, field);
            lua.gettable(L, -2);
            var type = lua.type(L, -1);

            lua.pop(L, 2);                                 StackAssert.End();
            return((LuaType)type);
        }
Пример #5
0
        /// <summary><see cref="RawGet(object)"/> alternative that only fetches plain Lua value types and strings.</summary>
        public LuaValue RawGetValue(LuaValue field)
        {
            field.VerifySupport("field");
            var L = Owner._L;

            luanet.checkstack(L, 2, "LuaTable.RawGetValue"); StackAssert.Start(L);
            push(L);
            field.push(L);
            lua.rawget(L, -2);
            var obj = LuaValue.read(L, -1, false);

            lua.pop(L, 2);                                    StackAssert.End();
            return(obj);
        }
Пример #6
0
        public void With_negative_rolls_moves_items_within_depth_range_down()
        {
            var stack = Stack
                        .Empty
                        .Push(666)
                        .Push(69)
                        .Push(17)
                        .Push(42)
                        .Push(3)
                        .Push(-1)
                        .Roll();

            StackAssert.AreEqual(stack, 69, 42, 17, 666);
        }
Пример #7
0
        /// <summary>Indexer alternative that only fetches plain Lua value types and strings.</summary>
        public LuaValue GetValue(LuaValue field)
        {
            field.VerifySupport("field");
            var L = Owner._L;

            luaclr.checkstack(L, 2, "LuaBase.GetValue"); StackAssert.Start(L);
            rawpush(L);
            field.push(L);
            lua.gettable(L, -2);
            var obj = LuaValue.read(L, -1, false);

            lua.pop(L, 2);                                StackAssert.End();
            return(obj);
        }
Пример #8
0
        /// <summary>Removes all entries from the table.</summary>
        public void Clear()
        {
            var L = Owner._L;

            luanet.checkstack(L, 4, "LuaTable.Clear"); StackAssert.Start(L);
            push(L);
            lua.pushnil(L);
            while (lua.next(L, -2))
            {
                lua.pop(L, 1);
                lua.pushvalue(L, -1);
                lua.pushnil(L);
                lua.rawset(L, -4);
            }
            lua.pop(L, 1);                              StackAssert.End();
        }
Пример #9
0
        /// <summary>Counts the number of entries in the table.</summary>
        public ulong LongCount()
        {
            var L = Owner._L;

            luanet.checkstack(L, 3, "LuaTable.LongCount"); StackAssert.Start(L);
            ulong count = 0;

            push(L);
            lua.pushnil(L);
            while (lua.next(L, -2))
            {
                ++count;
                lua.pop(L, 1);
            }
            lua.pop(L, 1);                                  StackAssert.End();
            return(count);
        }
Пример #10
0
        public ObjectTranslator(lua.State L, Lua interpreter)
        {
            Debug.Assert(interpreter.IsSameLua(L));
            luaclr.checkstack(L, 1, "new ObjectTranslator");
            this.interpreter = interpreter;
            typeChecker      = new CheckType(interpreter);
            metaFunctions    = new MetaFunctions(L, this);

            StackAssert.Start(L);
            lua.pushcfunction(L, _loadAssembly        = this.loadAssembly); lua.setglobal(L, "load_assembly");
            lua.pushcfunction(L, _importType          = this.importType); lua.setglobal(L, "import_type");
            lua.pushcfunction(L, _makeObject          = this.makeObject); lua.setglobal(L, "make_object");
            lua.pushcfunction(L, _freeObject          = this.freeObject); lua.setglobal(L, "free_object");
            lua.pushcfunction(L, _getMethodBysig      = this.getMethodBysig); lua.setglobal(L, "get_method_bysig");
            lua.pushcfunction(L, _getConstructorBysig = this.getConstructorBysig); lua.setglobal(L, "get_constructor_bysig");
            lua.pushcfunction(L, _ctype = this.ctype); lua.setglobal(L, "ctype");
            lua.pushcfunction(L, _enum  = this.@enum); lua.setglobal(L, "enum");
            StackAssert.End();
        }
Пример #11
0
 /// <summary>Indexer for nested string fields of the Lua object.</summary>
 public object this[params string[] path]
 {
     get
     {
         var L = Owner._L;
         luanet.checkstack(L, 1, "LuaBase.get_Indexer(String[])"); StackAssert.Start(L);
         rawpush(L);
         var ret = Owner.getNestedObject(L, -1, path);
         lua.pop(L, 1);                                             StackAssert.End();
         return(ret);
     }
     set
     {
         var L = Owner._L;
         luanet.checkstack(L, 1, "LuaBase.set_Indexer(String[])"); StackAssert.Start(L);
         rawpush(L);
         Owner.setNestedObject(L, -1, path, value);
         lua.pop(L, 1);                                             StackAssert.End();
     }
 }
Пример #12
0
        /// <summary>[-0, +1, m] Pushes a CLR object into the Lua stack as a userdata with the provided metatable</summary>
        void pushObject(lua.State L, object o)
        {
            Debug.Assert(interpreter.IsSameLua(L));
            if (o == null)
            {
                lua.pushnil(L);
                return;
            }
            luaL.checkstack(L, 3, "ObjectTranslator.pushObject");
            StackAssert.Start(L);

            luaclr.newref(L, o);

            // Gets or creates the metatable for the object's type
            if (luaclr.newrefmeta(L, o.GetType().AssemblyQualifiedName, 4))
            {
                metaFunctions.BuildObjectMetatable(L);
            }

            lua.setmetatable(L, -2);
            StackAssert.End(1);
        }
Пример #13
0
 /// <summary>Indexer for string fields of the Lua object.</summary>
 public object this[string field]
 {
     get
     {
         var L = Owner._L;
         luanet.checkstack(L, 2, "LuaBase.get_Indexer(String)"); StackAssert.Start(L);
         rawpush(L);
         lua.getfield(L, -1, field);
         var obj = Owner.translator.getObject(L, -1);
         lua.pop(L, 2);                                           StackAssert.End();
         return(obj);
     }
     set
     {
         var L = Owner._L;
         luanet.checkstack(L, 2, "LuaBase.set_Indexer(String)"); StackAssert.Start(L);
         rawpush(L);
         Owner.translator.push(L, value);
         lua.setfield(L, -2, field);
         lua.pop(L, 1);                                           StackAssert.End();
     }
 }
Пример #14
0
 /// <summary>Indexer for numeric fields of the Lua object.</summary>
 public object this[object field]
 {
     get
     {
         var L = Owner._L;
         luaclr.checkstack(L, 2, "LuaBase.get_Indexer(Object)"); StackAssert.Start(L);
         rawpush(L);
         Owner.translator.push(L, field);
         lua.gettable(L, -2);
         var obj = Owner.translator.getObject(L, -1);
         lua.pop(L, 2);                                           StackAssert.End();
         return(obj);
     }
     set
     {
         var L = Owner._L;
         luaclr.checkstack(L, 3, "LuaBase.set_Indexer(Object)"); StackAssert.Start(L);
         rawpush(L);
         Owner.translator.push(L, field);
         Owner.translator.push(L, value);
         lua.settable(L, -3);
         lua.pop(L, 1);                                           StackAssert.End();
     }
 }
Пример #15
0
        public void Removes_top_item_from_not_empty_stack()
        {
            var stack = Stack.Empty.Push(3).Push(17).Pop();

            StackAssert.AreEqual(stack, 3);
        }