Esempio n. 1
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);
            }
        }
Esempio n. 2
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);
            }
        }