| 345 | |
| 346 | |
| 347 | static 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 | |
| 379 | static int db_gethook (lua_State *L) { |
nothing calls this directly
no test coverage detected