MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaD_hook

Function luaD_hook

3rd/lua-5.4.3/src/ldo.c:306–339  ·  view source on GitHub ↗

** Call a hook for the given event. Make sure there is a hook to be ** called. (Both 'L->hook' and 'L->hookmask', which trigger this ** function, can be changed asynchronously by signals.) */

Source from the content-addressed store, hash-verified

304** function, can be changed asynchronously by signals.)
305*/
306void luaD_hook (lua_State *L, int event, int line,
307 int ftransfer, int ntransfer) {
308 lua_Hook hook = L->hook;
309 if (hook && L->allowhook) { /* make sure there is a hook */
310 int mask = CIST_HOOKED;
311 CallInfo *ci = L->ci;
312 ptrdiff_t top = savestack(L, L->top); /* preserve original 'top' */
313 ptrdiff_t ci_top = savestack(L, ci->top); /* idem for 'ci->top' */
314 lua_Debug ar;
315 ar.event = event;
316 ar.currentline = line;
317 ar.i_ci = ci;
318 if (ntransfer != 0) {
319 mask |= CIST_TRAN; /* 'ci' has transfer information */
320 ci->u2.transferinfo.ftransfer = ftransfer;
321 ci->u2.transferinfo.ntransfer = ntransfer;
322 }
323 if (isLua(ci) && L->top < ci->top)
324 L->top = ci->top; /* protect entire activation register */
325 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
326 if (ci->top < L->top + LUA_MINSTACK)
327 ci->top = L->top + LUA_MINSTACK;
328 L->allowhook = 0; /* cannot call hooks inside a hook */
329 ci->callstatus |= mask;
330 lua_unlock(L);
331 (*hook)(L, &ar);
332 lua_lock(L);
333 lua_assert(!L->allowhook);
334 L->allowhook = 1;
335 ci->top = restorestack(L, ci_top);
336 L->top = restorestack(L, top);
337 ci->callstatus &= ~mask;
338 }
339}
340
341
342/*

Callers 4

luaG_traceexecFunction · 0.85
luaD_hookcallFunction · 0.85
rethookFunction · 0.85
luaD_precallFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected