diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-12-08 13:47:25 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-12-08 13:47:25 -0200 |
commit | 6909b5a2b443040e09b575a6f320cd60d7e619ff (patch) | |
tree | 159bed7b3016ff6a93eea81d2c2d11669b00d404 /ldblib.c | |
parent | 594d7266af6c0a899e5218df444178c16327563e (diff) | |
download | lua-6909b5a2b443040e09b575a6f320cd60d7e619ff.tar.gz lua-6909b5a2b443040e09b575a6f320cd60d7e619ff.tar.bz2 lua-6909b5a2b443040e09b575a6f320cd60d7e619ff.zip |
In 'debug.gethook', does not query hook table (which may not exist) if
there is no hook set
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.145 2014/11/02 19:19:04 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.146 2014/11/10 14:27:16 roberto Exp roberto $ |
3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -345,10 +345,10 @@ static int db_sethook (lua_State *L) { | |||
345 | lua_pushvalue(L, -1); | 345 | lua_pushvalue(L, -1); |
346 | lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */ | 346 | lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */ |
347 | } | 347 | } |
348 | lua_pushthread(L1); lua_xmove(L1, L, 1); /* key */ | 348 | lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */ |
349 | lua_pushvalue(L, arg+1); /* value */ | 349 | lua_pushvalue(L, arg + 1); /* value (hook function) */ |
350 | lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */ | 350 | lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */ |
351 | lua_sethook(L1, func, mask, count); /* set hooks */ | 351 | lua_sethook(L1, func, mask, count); |
352 | return 0; | 352 | return 0; |
353 | } | 353 | } |
354 | 354 | ||
@@ -359,9 +359,11 @@ static int db_gethook (lua_State *L) { | |||
359 | char buff[5]; | 359 | char buff[5]; |
360 | int mask = lua_gethookmask(L1); | 360 | int mask = lua_gethookmask(L1); |
361 | lua_Hook hook = lua_gethook(L1); | 361 | lua_Hook hook = lua_gethook(L1); |
362 | if (hook != NULL && hook != hookf) /* external hook? */ | 362 | if (hook == NULL) /* no hook? */ |
363 | lua_pushnil(L); | ||
364 | else if (hook != hookf) /* external hook? */ | ||
363 | lua_pushliteral(L, "external hook"); | 365 | lua_pushliteral(L, "external hook"); |
364 | else { | 366 | else { /* hook table must exist */ |
365 | lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY); | 367 | lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY); |
366 | lua_pushthread(L1); lua_xmove(L1, L, 1); | 368 | lua_pushthread(L1); lua_xmove(L1, L, 1); |
367 | lua_rawget(L, -2); /* 1st result = hooktable[L1] */ | 369 | lua_rawget(L, -2); /* 1st result = hooktable[L1] */ |