MCPcopy Create free account
hub / github.com/DFHack/dfhack / db_sethook

Function db_sethook

depends/lua/src/ldblib.c:347–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345
346
347static int db_sethook (lua_State *L) {
348 int arg, mask, count;
349 lua_Hook func;
350 lua_State *L1 = getthread(L, &arg);
351 if (lua_isnoneornil(L, arg+1)) { /* no hook? */
352 lua_settop(L, arg+1);
353 func = NULL; mask = 0; count = 0; /* turn off hooks */
354 }
355 else {
356 const char *smask = luaL_checkstring(L, arg+2);
357 luaL_checktype(L, arg+1, LUA_TFUNCTION);
358 count = (int)luaL_optinteger(L, arg + 3, 0);
359 func = hookf; mask = makemask(smask, count);
360 }
361 if (lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY) == LUA_TNIL) {
362 lua_createtable(L, 0, 2); /* create a hook table */
363 lua_pushvalue(L, -1);
364 lua_rawsetp(L, LUA_REGISTRYINDEX, &HOOKKEY); /* set it in position */
365 lua_pushstring(L, "k");
366 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
367 lua_pushvalue(L, -1);
368 lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
369 }
370 checkstack(L, L1, 1);
371 lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */
372 lua_pushvalue(L, arg + 1); /* value (hook function) */
373 lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */
374 lua_sethook(L1, func, mask, count);
375 return 0;
376}
377
378
379static int db_gethook (lua_State *L) {

Callers

nothing calls this directly

Calls 15

getthreadFunction · 0.85
lua_settopFunction · 0.85
luaL_checktypeFunction · 0.85
luaL_optintegerFunction · 0.85
makemaskFunction · 0.85
lua_rawgetpFunction · 0.85
lua_createtableFunction · 0.85
lua_pushvalueFunction · 0.85
lua_rawsetpFunction · 0.85
lua_pushstringFunction · 0.85
lua_setfieldFunction · 0.85
lua_setmetatableFunction · 0.85

Tested by

no test coverage detected