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

Function luaD_precall

third-party/lua-5.4.6/src/ldo.c:595–624  ·  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

593** original function position.
594*/
595CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
596 retry:
597 switch (ttypetag(s2v(func))) {
598 case LUA_VCCL: /* C closure */
599 precallC(L, func, nresults, clCvalue(s2v(func))->f);
600 return NULL;
601 case LUA_VLCF: /* light C function */
602 precallC(L, func, nresults, fvalue(s2v(func)));
603 return NULL;
604 case LUA_VLCL: { /* Lua function */
605 CallInfo *ci;
606 Proto *p = clLvalue(s2v(func))->p;
607 int narg = cast_int(L->top.p - func) - 1; /* number of real arguments */
608 int nfixparams = p->numparams;
609 int fsize = p->maxstacksize; /* frame size */
610 checkstackGCp(L, fsize, func);
611 L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize);
612 ci->u.l.savedpc = p->code; /* starting point */
613 for (; narg < nfixparams; narg++)
614 setnilvalue(s2v(L->top.p++)); /* complete missing arguments */
615 lua_assert(ci->top.p <= L->stack_last.p);
616 return ci;
617 }
618 default: { /* not a function */
619 func = tryfuncTM(L, func); /* try to get '__call' metamethod */
620 /* return luaD_precall(L, func, nresults); */
621 goto retry; /* try again with metamethod */
622 }
623 }
624}
625
626
627/*

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