| 354 | |
| 355 | |
| 356 | static 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 | |
| 386 | static int db_gethook (lua_State *L) { |
nothing calls this directly
no test coverage detected