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