MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaD_precall

Function luaD_precall

third-party/lua-5.5.0/src/ldo.c:715–746  ·  view source on GitHub ↗

** Prepares the call to a function (C or Lua). For C functions, also do ** the call. The function to be called is at '*func'. The arguments ** are on the stack, right after the function. Returns the CallInfo ** to be executed, if it was a Lua function. Otherwise (a C function) ** returns NULL, with all the results on the stack, starting at the ** original function position. */

Source from the content-addressed store, hash-verified

713** original function position.
714*/
715CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
716 unsigned status = cast_uint(nresults + 1);
717 lua_assert(status <= MAXRESULTS + 1);
718 retry:
719 switch (ttypetag(s2v(func))) {
720 case LUA_VCCL: /* C closure */
721 precallC(L, func, status, clCvalue(s2v(func))->f);
722 return NULL;
723 case LUA_VLCF: /* light C function */
724 precallC(L, func, status, fvalue(s2v(func)));
725 return NULL;
726 case LUA_VLCL: { /* Lua function */
727 CallInfo *ci;
728 Proto *p = clLvalue(s2v(func))->p;
729 int narg = cast_int(L->top.p - func) - 1; /* number of real arguments */
730 int nfixparams = p->numparams;
731 int fsize = p->maxstacksize; /* frame size */
732 checkstackp(L, fsize, func);
733 L->ci = ci = prepCallInfo(L, func, status, func + 1 + fsize);
734 ci->u.l.savedpc = p->code; /* starting point */
735 for (; narg < nfixparams; narg++)
736 setnilvalue(s2v(L->top.p++)); /* complete missing arguments */
737 lua_assert(ci->top.p <= L->stack_last.p);
738 return ci;
739 }
740 default: { /* not a function */
741 checkstackp(L, 1, func); /* space for metamethod */
742 status = tryfuncTM(L, func, status); /* try '__call' metamethod */
743 goto retry; /* try again with metamethod */
744 }
745 }
746}
747
748
749/*

Callers 2

luaV_executeFunction · 0.70
ccallFunction · 0.70

Calls 3

precallCFunction · 0.70
prepCallInfoFunction · 0.70
tryfuncTMFunction · 0.70

Tested by

no test coverage detected