MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / db_sethook

Function db_sethook

third-party/lua-5.4.6/src/ldblib.c:365–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363
364
365static int db_sethook (lua_State *L) {
366 int arg, mask, count;
367 lua_Hook func;
368 lua_State *L1 = getthread(L, &arg);
369 if (lua_isnoneornil(L, arg+1)) { /* no hook? */
370 lua_settop(L, arg+1);
371 func = NULL; mask = 0; count = 0; /* turn off hooks */
372 }
373 else {
374 const char *smask = luaL_checkstring(L, arg+2);
375 luaL_checktype(L, arg+1, LUA_TFUNCTION);
376 count = (int)luaL_optinteger(L, arg + 3, 0);
377 func = hookf; mask = makemask(smask, count);
378 }
379 if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) {
380 /* table just created; initialize it */
381 lua_pushliteral(L, "k");
382 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
383 lua_pushvalue(L, -1);
384 lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */
385 }
386 checkstack(L, L1, 1);
387 lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */
388 lua_pushvalue(L, arg + 1); /* value (hook function) */
389 lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */
390 lua_sethook(L1, func, mask, count);
391 return 0;
392}
393
394
395static int db_gethook (lua_State *L) {

Callers

nothing calls this directly

Calls 14

getthreadFunction · 0.70
lua_settopFunction · 0.70
luaL_checktypeFunction · 0.70
luaL_optintegerFunction · 0.70
makemaskFunction · 0.70
luaL_getsubtableFunction · 0.70
lua_setfieldFunction · 0.70
lua_pushvalueFunction · 0.70
lua_setmetatableFunction · 0.70
checkstackFunction · 0.70
lua_pushthreadFunction · 0.70
lua_xmoveFunction · 0.70

Tested by

no test coverage detected