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