/* Initialize call. Ensure stack space and return # of missing parameters. */ static int call_init(lua_State *L, GCfunc *fn) { if (isluafunc(fn)) { GCproto *pt = funcproto(fn); int numparams = pt->numparams; int gotparams = (int)(L->top - L->base); int need = pt->framesize; if ((pt->flags & PROTO_IS_VARARG)) need += 1+gotparams; lj_state_checkstack(L, (MSize)need); numparams -= gotparams; return numparams >= 0 ? numparams : 0; } else { lj_state_checkstack(L, LUA_MINSTACK); return 0; } }
ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev) { global_State *g = G(L); GCstr *s = lj_str_newlit(L, LJ_VMEVENTS_REGKEY); cTValue *tv = lj_tab_getstr(tabV(registry(L)), s); if (tvistab(tv)) { int hash = VMEVENT_HASH(ev); tv = lj_tab_getint(tabV(tv), hash); if (tv && tvisfunc(tv)) { lj_state_checkstack(L, LUA_MINSTACK); setfuncV(L, L->top++, funcV(tv)); return savestack(L, L->top); } } g->vmevmask &= ~VMEVENT_MASK(ev); /* No handler: cache this fact. */ return 0; }
/* Call a hook. */ static void callhook(lua_State *L, int event, BCLine line) { global_State *g = G(L); lua_Hook hookf = g->hookf; if (hookf && !hook_active(g)) { lua_Debug ar; lj_trace_abort(g); /* Abort recording on any hook call. */ ar.event = event; ar.currentline = line; ar.i_ci = cast_int((L->base-1) - L->stack); /* Top frame, nextframe=NULL. */ lj_state_checkstack(L, 1+LUA_MINSTACK); hook_enter(g); hookf(L, &ar); lua_assert(hook_active(g)); hook_leave(g); } }
static int io_file_iter(lua_State *L) { GCfunc *fn = curr_func(L); IOFileUD *iof = uddata(udataV(&fn->c.upvalue[0])); int n = fn->c.nupvalues - 1; if (iof->fp == NULL) lj_err_caller(L, LJ_ERR_IOCLFL); L->top = L->base; if (n) { /* Copy upvalues with options to stack. */ if (n > LUAI_MAXCSTACK) lj_err_caller(L, LJ_ERR_STKOV); lj_state_checkstack(L, (MSize)n); memcpy(L->top, &fn->c.upvalue[1], n*sizeof(TValue)); L->top += n; } n = io_file_read(L, iof->fp, 0); if (ferror(iof->fp)) lj_err_callermsg(L, strVdata(L->top-2)); if (tvisnil(L->base) && (iof->type & IOFILE_FLAG_CLOSE)) { io_file_close(L, iof); /* Return values are ignored. */ return 0; } return n; }