MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / luaD_pretailcall

Function luaD_pretailcall

xrepo/packages/l/lua/port/lua/src/ldo.c:520–554  ·  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

518** results, if it was a C function, or -1 for a Lua function.
519*/
520int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
521 int narg1, int delta) {
522 retry:
523 switch (ttypetag(s2v(func))) {
524 case LUA_VCCL: /* C closure */
525 return precallC(L, func, LUA_MULTRET, clCvalue(s2v(func))->f);
526 case LUA_VLCF: /* light C function */
527 return precallC(L, func, LUA_MULTRET, fvalue(s2v(func)));
528 case LUA_VLCL: { /* Lua function */
529 Proto *p = clLvalue(s2v(func))->p;
530 int fsize = p->maxstacksize; /* frame size */
531 int nfixparams = p->numparams;
532 int i;
533 checkstackGCp(L, fsize - delta, func);
534 ci->func -= delta; /* restore 'func' (if vararg) */
535 for (i = 0; i < narg1; i++) /* move down function and arguments */
536 setobjs2s(L, ci->func + i, func + i);
537 func = ci->func; /* moved-down function */
538 for (; narg1 <= nfixparams; narg1++)
539 setnilvalue(s2v(func + narg1)); /* complete missing arguments */
540 ci->top = func + 1 + fsize; /* top for new function */
541 lua_assert(ci->top <= L->stack_last);
542 ci->u.l.savedpc = p->code; /* starting point */
543 ci->callstatus |= CIST_TAIL;
544 L->top = func + narg1; /* set top */
545 return -1;
546 }
547 default: { /* not a function */
548 func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
549 /* return luaD_pretailcall(L, ci, func, narg1 + 1, delta); */
550 narg1++;
551 goto retry; /* try again */
552 }
553 }
554}
555
556
557/*

Callers 1

luaV_executeFunction · 0.85

Calls 2

precallCFunction · 0.85
luaD_tryfuncTMFunction · 0.85

Tested by

no test coverage detected