Exemplo n.º 1
0
    def call_lua_closure(self, nargs, nresults, c):
        nregs = c.proto.get_max_stack_size()
        nparams = c.proto.get_num_params()
        is_vararg = c.proto.get_is_vararg()

        # create new lua stack
        new_stack = LuaStack(self)
        new_stack.closure = c

        # pass args, pop func
        func_and_args = self.stack.popn(nargs + 1)
        new_stack.pushn(func_and_args[1:], nparams)
        if nargs > nparams and is_vararg:
            new_stack.varargs = func_and_args[nparams + 1:]

        # run closure
        self.push_lua_stack(new_stack)
        self.set_top(nregs)
        self.run_lua_closure()
        self.pop_lua_stack()

        # return results
        if nresults != 0:
            results = new_stack.popn(new_stack.top() - nregs)
            self.stack.check(len(results))
            self.stack.pushn(results, nresults)
Exemplo n.º 2
0
    def call_py_closure(self, nargs, nresults, c):
        new_stack = LuaStack(self)
        new_stack.closure = c

        args = self.stack.popn(nargs)
        new_stack.pushn(args, nargs)
        self.stack.pop()

        self.push_lua_stack(new_stack)
        r = c.py_func(self)
        self.pop_lua_stack()

        if nresults != 0:
            results = new_stack.popn(r)
            self.stack.check(len(results))
            self.stack.pushn(results, nresults)