MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / db_sethook

Function db_sethook

extlibs/lua/src/ldblib.c:356–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354
355
356static int db_sethook (lua_State *L) {
357 int arg, mask, count;
358 lua_Hook func;
359 lua_State *L1 = getthread(L, &arg);
360 if (lua_isnoneornil(L, arg+1)) { /* no hook? */
361 lua_settop(L, arg+1);
362 func = NULL; mask = 0; count = 0; /* turn off hooks */
363 }
364 else {
365 const char *smask = luaL_checkstring(L, arg+2);
366 luaL_checktype(L, arg+1, LUA_TFUNCTION);
367 count = (int)luaL_optinteger(L, arg + 3, 0);
368 func = hookf; mask = makemask(smask, count);
369 }
370 if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) {
371 /* table just created; initialize it */
372 lua_pushstring(L, "k");
373 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
374 lua_pushvalue(L, -1);
375 lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */
376 }
377 checkstack(L, L1, 1);
378 lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */
379 lua_pushvalue(L, arg + 1); /* value (hook function) */
380 lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */
381 lua_sethook(L1, func, mask, count);
382 return 0;
383}
384
385
386static 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_pushstringFunction · 0.85
lua_setfieldFunction · 0.85
lua_pushvalueFunction · 0.85
lua_setmetatableFunction · 0.85
checkstackFunction · 0.85
lua_pushthreadFunction · 0.85
lua_xmoveFunction · 0.85

Tested by

no test coverage detected