Exemple #1
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);
            }
        }
Exemple #2
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);
            }
        }