| 302 | |
| 303 | |
| 304 | static int db_sethook (lua_State *L) { |
| 305 | int arg, mask, count; |
| 306 | lua_Hook func; |
| 307 | lua_State *L1 = getthread(L, &arg); |
| 308 | if (lua_isnoneornil(L, arg+1)) { |
| 309 | lua_settop(L, arg+1); |
| 310 | func = NULL; mask = 0; count = 0; /* turn off hooks */ |
| 311 | } |
| 312 | else { |
| 313 | const char *smask = luaL_checkstring(L, arg+2); |
| 314 | luaL_checktype(L, arg+1, LUA_TFUNCTION); |
| 315 | count = luaL_optint(L, arg+3, 0); |
| 316 | func = hookf; mask = makemask(smask, count); |
| 317 | } |
| 318 | if (gethooktable(L) == 0) { /* creating hook table? */ |
| 319 | lua_pushstring(L, "k"); |
| 320 | lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */ |
| 321 | lua_pushvalue(L, -1); |
| 322 | lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */ |
| 323 | } |
| 324 | checkstack(L, L1, 1); |
| 325 | lua_pushthread(L1); lua_xmove(L1, L, 1); |
| 326 | lua_pushvalue(L, arg+1); |
| 327 | lua_rawset(L, -3); /* set new hook */ |
| 328 | lua_sethook(L1, func, mask, count); /* set hooks */ |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | |
| 333 | static int db_gethook (lua_State *L) { |
nothing calls this directly
no test coverage detected