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

Function db_sethook

third-party/lua-5.5.0/src/ldblib.c:368–395  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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