MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / luaD_call

Function luaD_call

extlibs/lua/src/ldo.c:458–513  ·  view source on GitHub ↗

** Call a function (C or Lua). The function to be called is at *func. ** The arguments are on the stack, right after the function. ** When returns, all the results are on the stack, starting at the original ** function position. */

Source from the content-addressed store, hash-verified

456** function position.
457*/
458void luaD_call (lua_State *L, StkId func, int nresults) {
459 lua_CFunction f;
460 retry:
461 switch (ttypetag(s2v(func))) {
462 case LUA_VCCL: /* C closure */
463 f = clCvalue(s2v(func))->f;
464 goto Cfunc;
465 case LUA_VLCF: /* light C function */
466 f = fvalue(s2v(func));
467 Cfunc: {
468 int n; /* number of returns */
469 CallInfo *ci;
470 checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
471 ci = next_ci(L);
472 ci->nresults = nresults;
473 ci->callstatus = CIST_C;
474 ci->top = L->top + LUA_MINSTACK;
475 ci->func = func;
476 lua_assert(ci->top <= L->stack_last);
477 if (L->hookmask & LUA_MASKCALL) {
478 int narg = cast_int(L->top - func) - 1;
479 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg);
480 }
481 lua_unlock(L);
482 n = (*f)(L); /* do the actual call */
483 lua_lock(L);
484 api_checknelems(L, n);
485 luaD_poscall(L, ci, n);
486 break;
487 }
488 case LUA_VLCL: { /* Lua function */
489 CallInfo *ci;
490 Proto *p = clLvalue(s2v(func))->p;
491 int narg = cast_int(L->top - func) - 1; /* number of real arguments */
492 int nfixparams = p->numparams;
493 int fsize = p->maxstacksize; /* frame size */
494 checkstackp(L, fsize, func);
495 ci = next_ci(L);
496 ci->nresults = nresults;
497 ci->u.l.savedpc = p->code; /* starting point */
498 ci->callstatus = 0;
499 ci->top = func + 1 + fsize;
500 ci->func = func;
501 for (; narg < nfixparams; narg++)
502 setnilvalue(s2v(L->top++)); /* complete missing arguments */
503 lua_assert(ci->top <= L->stack_last);
504 luaV_execute(L, ci); /* run the function */
505 break;
506 }
507 default: { /* not a function */
508 checkstackp(L, 1, func); /* space for metamethod */
509 luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
510 goto retry; /* try again with metamethod */
511 }
512 }
513}
514
515

Callers 7

luaV_executeFunction · 0.85
luaT_callTMFunction · 0.85
luaT_callTMresFunction · 0.85
luaD_callnoyieldFunction · 0.85
resumeFunction · 0.85
lua_callkFunction · 0.85
lua_pcallkFunction · 0.85

Calls 4

luaD_hookFunction · 0.85
luaD_poscallFunction · 0.85
luaV_executeFunction · 0.85
luaD_tryfuncTMFunction · 0.85

Tested by

no test coverage detected