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

Function luaD_pretailcall

third-party/lua-5.4.6/src/ldo.c:550–584  ·  view source on GitHub ↗

** Prepare a function for a tail call, building its call info on top ** of the current call info. 'narg1' is the number of arguments plus 1 ** (so that it includes the function itself). Return the number of ** results, if it was a C function, or -1 for a Lua function. */

Source from the content-addressed store, hash-verified

548** results, if it was a C function, or -1 for a Lua function.
549*/
550int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
551 int narg1, int delta) {
552 retry:
553 switch (ttypetag(s2v(func))) {
554 case LUA_VCCL: /* C closure */
555 return precallC(L, func, LUA_MULTRET, clCvalue(s2v(func))->f);
556 case LUA_VLCF: /* light C function */
557 return precallC(L, func, LUA_MULTRET, fvalue(s2v(func)));
558 case LUA_VLCL: { /* Lua function */
559 Proto *p = clLvalue(s2v(func))->p;
560 int fsize = p->maxstacksize; /* frame size */
561 int nfixparams = p->numparams;
562 int i;
563 checkstackGCp(L, fsize - delta, func);
564 ci->func.p -= delta; /* restore 'func' (if vararg) */
565 for (i = 0; i < narg1; i++) /* move down function and arguments */
566 setobjs2s(L, ci->func.p + i, func + i);
567 func = ci->func.p; /* moved-down function */
568 for (; narg1 <= nfixparams; narg1++)
569 setnilvalue(s2v(func + narg1)); /* complete missing arguments */
570 ci->top.p = func + 1 + fsize; /* top for new function */
571 lua_assert(ci->top.p <= L->stack_last.p);
572 ci->u.l.savedpc = p->code; /* starting point */
573 ci->callstatus |= CIST_TAIL;
574 L->top.p = func + narg1; /* set top */
575 return -1;
576 }
577 default: { /* not a function */
578 func = tryfuncTM(L, func); /* try to get '__call' metamethod */
579 /* return luaD_pretailcall(L, ci, func, narg1 + 1, delta); */
580 narg1++;
581 goto retry; /* try again */
582 }
583 }
584}
585
586
587/*

Callers 1

luaV_executeFunction · 0.70

Calls 2

precallCFunction · 0.70
tryfuncTMFunction · 0.70

Tested by

no test coverage detected