Exemplo n.º 1
0
        public IEnumerator <StackIndexChild> GetEnumerator()
        {
            _log("GetEnumerator()");
            var L = Parent.L;

            luanet.checkstack(L, 3, "StackIndexChild.GetEnumerator");
            var results = new List <StackIndexChild>();

            this.push();
            Dbg.Assert(_keys.All(k => k.IsSupported));
            if (lua.type(L, -1) == LUA.T.TABLE)
            {
                StackAssert.Start(L);
                lua.pushnil(L);
                while (lua.next(L, -2))
                {
                    var keys = new LuaValue[_keys.Length + 1];
                    Array.Copy(_keys, keys, _keys.Length);
                    keys[keys.Length - 1] = LuaValue.read(L, -2, true);
                    results.Add(new StackIndexChild(this.Parent, keys));
                    lua.pop(L, 1);
                }
                StackAssert.End();
            }
            lua.pop(L, 1);
            return(results.GetEnumerator());
        }
Exemplo n.º 2
0
        public void push()
        {
            _keys[_keys.Length - 1].VerifySupport();
            var L = Parent.L;

            luanet.checkstack(L, 2, "StackIndexChild.push"); StackAssert.Start(L);
            Dbg.Assert(_keys.All(k => k.IsSupported));
            var keys = _keys;

            lua.CFunction tryBlock = L2 =>
            {
                for (int i = 0; i < keys.Length; ++i)
                {
                    keys[i].push(L2);
                    lua.gettable(L2, -2);
                    lua.remove(L2, -2);
                }
                return(1);
            };
            // parent should be pushed first. it might be pointing to the index we're about to fill
            this.Parent.push();
            lua.pushcfunction(L, tryBlock);
            lua.insert(L, -2);
            var ex = luanet.pcall(L, 1, 1);

            if (ex != null)
            {
                StackAssert.End();
                Trace.TraceError("push failed: " + ex.Message);
                throw ex;
            }
            GC.KeepAlive(tryBlock);                          StackAssert.End(1);
        }
Exemplo n.º 3
0
 /// <summary>
 /// [-0, +1, e] Navigates fields nested in an object at the specified index, pushing the value of the specified sub-field. If <paramref name="fields"/> is empty it pushes a copy of the main object.
 /// <para>WARNING: If the IEnumerable throws an exception during enumeration the stack will be left in a +1 state. You must ensure that no exceptions can be thrown or you must catch them and clean up the stack.</para>
 /// </summary>
 public static void getnestedfield(lua.State L, int index, IEnumerable <string> fields)
 {
     luaL.checkstack(L, 2, "luanet.getnestedfield");
     Debug.Assert(fields != null);                StackAssert.Start(L);
     lua.pushvalue(L, index);
     foreach (string field in fields)
     {
         lua.getfield(L, -1, field);
         lua.remove(L, -2);
     }
     StackAssert.End(1);
 }
Exemplo n.º 4
0
        public IEnumerator <StackIndexChild> GetEnumerator()
        {
            _log("GetEnumerator()");
            luanet.checkstack(L, 2, "StackIndex.GetEnumerator");
            L.NullCheck();
            var results = new List <StackIndexChild>();
            int index   = luanet.absoluteindex(L, Index);

            if (index != 0 && lua.type(L, index) == LUA.T.TABLE)
            {
                StackAssert.Start(L);
                lua.pushnil(L);
                while (lua.next(L, index))
                {
                    results.Add(new StackIndexChild(this, new[] { LuaValue.read(L, -2, true) }));
                    lua.pop(L, 1);
                }
                StackAssert.End();
            }
            return(results.GetEnumerator());
        }