MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / luaD_precall

Function luaD_precall

Source/Misc/lua/src/lua.c:5410–5474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5408
5409
5410int luaD_precall (lua_State *L, StkId func, int nresults) {
5411LClosure *cl;
5412ptrdiff_t funcr;
5413if (!ttisfunction(func)) /* `func' is not a function? */
5414func = tryfuncTM(L, func); /* check the `function' tag method */
5415funcr = savestack(L, func);
5416cl = &clvalue(func)->l;
5417L->ci->savedpc = L->savedpc;
5418if (!cl->isC) { /* Lua function? prepare its call */
5419CallInfo *ci;
5420StkId st, base;
5421Proto *p = cl->p;
5422luaD_checkstack(L, p->maxstacksize);
5423func = restorestack(L, funcr);
5424if (!p->is_vararg) { /* no varargs? */
5425base = func + 1;
5426if (L->top > base + p->numparams)
5427L->top = base + p->numparams;
5428}
5429else { /* vararg function */
5430int nargs = cast_int(L->top - func) - 1;
5431base = adjust_varargs(L, p, nargs);
5432func = restorestack(L, funcr); /* previous call may change the stack */
5433}
5434ci = inc_ci(L); /* now `enter' new function */
5435ci->func = func;
5436L->base = ci->base = base;
5437ci->top = L->base + p->maxstacksize;
5438lua_assert(ci->top <= L->stack_last);
5439L->savedpc = p->code; /* starting point */
5440ci->tailcalls = 0;
5441ci->nresults = nresults;
5442for (st = L->top; st < ci->top; st++)
5443setnilvalue(st);
5444L->top = ci->top;
5445if (L->hookmask & LUA_MASKCALL) {
5446L->savedpc++; /* hooks assume 'pc' is already incremented */
5447luaD_callhook(L, LUA_HOOKCALL, -1);
5448L->savedpc--; /* correct 'pc' */
5449}
5450return PCRLUA;
5451}
5452else { /* if is a C function, call it */
5453CallInfo *ci;
5454int n;
5455luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
5456ci = inc_ci(L); /* now `enter' new function */
5457ci->func = restorestack(L, funcr);
5458L->base = ci->base = ci->func + 1;
5459ci->top = L->top + LUA_MINSTACK;
5460lua_assert(ci->top <= L->stack_last);
5461ci->nresults = nresults;
5462if (L->hookmask & LUA_MASKCALL)
5463luaD_callhook(L, LUA_HOOKCALL, -1);
5464lua_unlock(L);
5465n = (*curr_func(L)->c.f)(L); /* do the actual call */
5466lua_lock(L);
5467if (n < 0) /* yielding? */

Callers 3

luaD_callFunction · 0.85
resumeFunction · 0.85
luaV_executeFunction · 0.85

Calls 4

tryfuncTMFunction · 0.85
adjust_varargsFunction · 0.85
luaD_callhookFunction · 0.85
luaD_poscallFunction · 0.85

Tested by

no test coverage detected