| 363 | |
| 364 | |
| 365 | static 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 | |
| 395 | static int db_gethook (lua_State *L) { |
nothing calls this directly
no test coverage detected