Ejemplo n.º 1
0
        public void PopLuaStack()
        {
            var stack = _stack;

            _stack     = stack.Prev;
            stack.Prev = null;
        }
Ejemplo n.º 2
0
        private 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;

            var newStack = new LuaStack(nRegs + Consts.LUA_MINSTACK, this)
            {
                Closure = c
            };

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

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

            // 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.º 3
0
        private void CallCSClosure(int nArgs, int nResults, Closure c)
        {
            var newStack = new LuaStack(nArgs + Consts.LUA_MINSTACK, this)
            {
                Closure = c
            };

            var args = _stack.PopN(nArgs);

            newStack.PushN(args, nArgs);
            _stack.Pop();

            PushLuaStack(newStack);
            var r = c.CSFunction(this);

            PopLuaStack();

            if (nResults != 0)
            {
                var results = newStack.PopN(r);
                _stack.Check(results.Length);
                _stack.PushN(results, nResults);
            }
        }
Ejemplo n.º 4
0
 public void PushLuaStack(LuaStack stack)
 {
     stack.Prev = _stack;
     _stack     = stack;
 }