** returns true if function has been executed (C function) */
| 364 | ** returns true if function has been executed (C function) |
| 365 | */ |
| 366 | int luaD_precall (lua_State *L, StkId func, int nresults) { |
| 367 | lua_CFunction f; |
| 368 | CallInfo *ci; |
| 369 | int n; /* number of arguments (Lua) or returns (C) */ |
| 370 | ptrdiff_t funcr = savestack(L, func); |
| 371 | switch (ttype(func)) { |
| 372 | case LUA_TLCF: /* light C function */ |
| 373 | f = fvalue(func); |
| 374 | goto Cfunc; |
| 375 | case LUA_TCCL: { /* C closure */ |
| 376 | f = clCvalue(func)->f; |
| 377 | Cfunc: |
| 378 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
| 379 | ci = next_ci(L); /* now 'enter' new function */ |
| 380 | ci->nresults = nresults; |
| 381 | ci->func = restorestack(L, funcr); |
| 382 | ci->top = L->top + LUA_MINSTACK; |
| 383 | lua_assert(ci->top <= L->stack_last); |
| 384 | ci->callstatus = 0; |
| 385 | luaC_checkGC(L); /* stack grow uses memory */ |
| 386 | if (L->hookmask & LUA_MASKCALL) |
| 387 | luaD_hook(L, LUA_HOOKCALL, -1); |
| 388 | lua_unlock(L); |
| 389 | n = (*f)(L); /* do the actual call */ |
| 390 | lua_lock(L); |
| 391 | api_checknelems(L, n); |
| 392 | luaD_poscall(L, L->top - n); |
| 393 | return 1; |
| 394 | } |
| 395 | case LUA_TLCL: { /* Lua function: prepare its call */ |
| 396 | StkId base; |
| 397 | Proto *p = clLvalue(func)->p; |
| 398 | n = cast_int(L->top - func) - 1; /* number of real arguments */ |
| 399 | luaD_checkstack(L, p->maxstacksize); |
| 400 | for (; n < p->numparams; n++) |
| 401 | setnilvalue(L->top++); /* complete missing arguments */ |
| 402 | if (!p->is_vararg) { |
| 403 | func = restorestack(L, funcr); |
| 404 | base = func + 1; |
| 405 | } |
| 406 | else { |
| 407 | base = adjust_varargs(L, p, n); |
| 408 | func = restorestack(L, funcr); /* previous call can change stack */ |
| 409 | } |
| 410 | ci = next_ci(L); /* now 'enter' new function */ |
| 411 | ci->nresults = nresults; |
| 412 | ci->func = func; |
| 413 | ci->u.l.base = base; |
| 414 | ci->top = base + p->maxstacksize; |
| 415 | lua_assert(ci->top <= L->stack_last); |
| 416 | ci->u.l.savedpc = p->code; /* starting point */ |
| 417 | ci->callstatus = CIST_LUA; |
| 418 | L->top = ci->top; |
| 419 | luaC_checkGC(L); /* stack grow uses memory */ |
| 420 | if (L->hookmask & LUA_MASKCALL) |
| 421 | callhook(L, ci); |
| 422 | return 0; |
| 423 | } |
no test coverage detected