Ejemplo n.º 1
0
        private void popLuaStack()
        {
            var stack = this.stack;

            this.stack = stack.prev;
            stack.prev = null;
        }
Ejemplo n.º 2
0
        private void callCsharpClosure(int nArgs, int nResults, Closure c)
        {
            // create new lua stack
            var newStack = LuaStack.newLuaStack(nArgs + Consts.LUA_MINSTACK, this);

            newStack.closure = c;

            // pass args, pop func
            var args = stack.popN(nArgs);

            newStack.pushN(args, nArgs);
            stack.pop();

            // run closure
            pushLuaStack(newStack);
            var r = c.csharpFunc(this);

            popLuaStack();

            // return results
            if (nResults != 0)
            {
                var results = newStack.popN(r);
                stack.check(results.Length);
                stack.pushN(results, nResults);
            }
        }
Ejemplo n.º 3
0
        void callLuaClosure(int nArgs, int nResults, Closure c)
        {
            var nRegs    = (int)c.proto.MaxStackSize;
            var nParams  = (int)c.proto.NumParams;
            var isVararg = c.proto.IsVararg == 1;

            // create new lua stack
            var newStack = LuaStack.newLuaStack(nRegs + Consts.LUA_MINSTACK, this);

            newStack.closure = c;

            // pass args, pop func
            var funcAndArgs = stack.popN(nArgs + 1);

            newStack.pushN(funcAndArgs.Skip(1).ToArray(), nParams);
            newStack.top = nRegs;
            if (nArgs > nParams && isVararg)
            {
                newStack.varargs = funcAndArgs.Skip(nParams + 1).ToArray();
            }

            // run closure
            pushLuaStack(newStack);
            runLuaClosure();
            popLuaStack();

            // return results
            if (nResults != 0)
            {
                var results = newStack.popN(newStack.top - nRegs);
                stack.check(results.Length);
                stack.pushN(results, nResults);
            }
        }
Ejemplo n.º 4
0
        private void callCsharpClosure(int nArgs, int nResults, Closure c)
        {
            // create new lua stack
            var newStack = new LuaStack {
                state = this, closure = c
            };

            // pass args, pop func
            if (nArgs > 0)
            {
                newStack.pushN(stack.popN(nArgs), nArgs);
            }

            stack.pop();

            // run closure
            pushLuaStack(newStack);
            var r = c.csharpFunc(this);

            popLuaStack();

            // return results
            if (nResults != 0)
            {
                var results = newStack.popN(r);
                //stack.check(results.Length);
                stack.pushN(results, nResults);
            }
        }
Ejemplo n.º 5
0
        private void popLuaStack()
        {
            var top = stack;

            stack    = top.prev;
            top.prev = null;
        }
Ejemplo n.º 6
0
        void callLuaClosure(int nArgs, int nResults, Closure c)
        {
            var nRegs    = c.proto.MaxStackSize;
            var nParams  = c.proto.NumParams;
            var isVararg = c.proto.IsVararg == 1;

            // create new lua stack
            var newStack = new LuaStack {
                closure = c
            };

            // pass args, pop func
            var funcAndArgs = stack.popN(nArgs + 1);

            newStack.pushN(funcAndArgs.Skip(1).ToArray().ToList(), nParams);
            if (nArgs > nParams && isVararg)
            {
                newStack.varargs = funcAndArgs.Skip(nParams + 1).ToArray().ToList();
            }

            // run closure
            pushLuaStack(newStack);
            SetTop(nRegs);
            runLuaClosure();
            popLuaStack();

            // return results
            if (nResults != 0)
            {
                var results = newStack.popN(newStack.top() - nRegs);
                //stack.check(results.size())
                stack.pushN(results, nResults);
            }
        }
Ejemplo n.º 7
0
 public static api.LuaState New(int stackSize)
 {
     return(new LuaState
     {
         stack = LuaStack.newLuaStack(stackSize)
     });
 }
Ejemplo n.º 8
0
        private void CallLuaClosure(int nArgs, int nResults, Closure c)
        {
            var nRegs    = c.Proto.MaxStackSize;
            var nParams  = c.Proto.NumParams;
            var isVararg = c.Proto.IsVararg == 1;

            // create new lua stack
            var newStack = new LuaStack {
                Closure = c
            };

            // pass args, pop func
            var funcAndArgs = _stack.PopN(nArgs + 1);
            var count       = funcAndArgs.Count - 1;

            newStack.PushN(funcAndArgs.GetRange(1, count), nParams);
            if (nArgs > nParams && isVararg)
            {
                newStack.Varargs = funcAndArgs.GetRange(nParams + 1, count);
            }

            // run closure
            PushLuaStack(newStack);
            SetTop(nRegs);
            RunLuaClosure();
            PopLuaStack();

            // return results
            if (nResults != 0)
            {
                var results = newStack.PopN(newStack.Top() - nRegs);
                //stack.check(results.size())
                _stack.PushN(results, nResults);
            }
        }
Ejemplo n.º 9
0
        internal void popLuaStack()
        {
            var stack = this.stack;

            this.stack = stack.prev;
            stack.prev = null;
        }
Ejemplo n.º 10
0
        private void PopLuaStack()
        {
            var top = _stack;

            _stack   = top.Prev;
            top.Prev = null;
        }
Ejemplo n.º 11
0
 public api.LuaState New(int stackSize, Prototype proto)
 {
     return(new LuaState
     {
         stack = LuaStack.newLuaStack(stackSize),
         proto = proto,
         pc = 0
     });
 }
Ejemplo n.º 12
0
        public static api.LuaState New()
        {
            var registry = LuaTable.newLuaTable(0, 0);

            registry.put(Consts.LUA_RIDX_GLOBALS, LuaTable.newLuaTable(0, 0));

            var ls = new LuaState
            {
                registry = registry
            };

            ls.pushLuaStack(LuaStack.newLuaStack(Consts.LUA_MINSTACK, ls));
            return(ls);
        }
Ejemplo n.º 13
0
        public LuaState()
        {
            registry.put(Consts.LUA_RIDX_GLOBALS, new LuaTable(0, 0));
            LuaStack stack = new LuaStack();

            stack.state = this;
            pushLuaStack(stack);
//            var registry = LuaTable.newLuaTable(0, 0);
//            registry.put(Consts.LUA_RIDX_GLOBALS, LuaTable.newLuaTable(0, 0));
//
//            var ls = new LuaState
//            {
//                registry = registry
//            };
//            ls.pushLuaStack(LuaStack.newLuaStack(Consts.LUA_MINSTACK, ls));
//            return ls;
        }
Ejemplo n.º 14
0
 private void pushLuaStack(LuaStack stack)
 {
     stack.prev = this.stack;
     this.stack = stack;
 }
Ejemplo n.º 15
0
 internal void pushLuaStack(LuaStack stack)
 {
     stack.prev = this.stack;
     this.stack = stack;
 }
Ejemplo n.º 16
0
 private void PushLuaStack(LuaStack stack)
 {
     stack.Prev  = this._stack;
     this._stack = stack;
 }