diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-01-10 13:51:19 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-01-10 13:51:19 -0200 |
commit | c2e3cc4c89ccd058c84e1d14499c8b26d99c5b3d (patch) | |
tree | 8eaf52fda47a0f9ae865fdc0072e678fd38e8685 /ldblib.c | |
parent | 67feed49f189e8e6318a5ef63461e10e2d174a82 (diff) | |
download | lua-c2e3cc4c89ccd058c84e1d14499c8b26d99c5b3d.tar.gz lua-c2e3cc4c89ccd058c84e1d14499c8b26d99c5b3d.tar.bz2 lua-c2e3cc4c89ccd058c84e1d14499c8b26d99c5b3d.zip |
using 'luaL_findtable' to manage hook table
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 23 |
1 files changed, 6 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.126 2010/11/16 18:01:28 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.127 2010/12/20 17:24:15 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 | */ |
@@ -18,6 +18,9 @@ | |||
18 | #include "lualib.h" | 18 | #include "lualib.h" |
19 | 19 | ||
20 | 20 | ||
21 | #define HOOKKEY "_HKEY" | ||
22 | |||
23 | |||
21 | 24 | ||
22 | static int db_getregistry (lua_State *L) { | 25 | static int db_getregistry (lua_State *L) { |
23 | lua_pushvalue(L, LUA_REGISTRYINDEX); | 26 | lua_pushvalue(L, LUA_REGISTRYINDEX); |
@@ -250,14 +253,13 @@ static int db_upvaluejoin (lua_State *L) { | |||
250 | } | 253 | } |
251 | 254 | ||
252 | 255 | ||
253 | static const char KEY_HOOK = 'h'; | 256 | #define gethooktable(L) luaL_findtable(L, LUA_REGISTRYINDEX, HOOKKEY); |
254 | 257 | ||
255 | 258 | ||
256 | static void hookf (lua_State *L, lua_Debug *ar) { | 259 | static void hookf (lua_State *L, lua_Debug *ar) { |
257 | static const char *const hooknames[] = | 260 | static const char *const hooknames[] = |
258 | {"call", "return", "line", "count", "tail call"}; | 261 | {"call", "return", "line", "count", "tail call"}; |
259 | lua_pushlightuserdata(L, (void *)&KEY_HOOK); | 262 | gethooktable(L); |
260 | lua_rawget(L, LUA_REGISTRYINDEX); | ||
261 | lua_pushlightuserdata(L, L); | 263 | lua_pushlightuserdata(L, L); |
262 | lua_rawget(L, -2); | 264 | lua_rawget(L, -2); |
263 | if (lua_isfunction(L, -1)) { | 265 | if (lua_isfunction(L, -1)) { |
@@ -291,19 +293,6 @@ static char *unmakemask (int mask, char *smask) { | |||
291 | } | 293 | } |
292 | 294 | ||
293 | 295 | ||
294 | static void gethooktable (lua_State *L) { | ||
295 | lua_pushlightuserdata(L, (void *)&KEY_HOOK); | ||
296 | lua_rawget(L, LUA_REGISTRYINDEX); | ||
297 | if (!lua_istable(L, -1)) { | ||
298 | lua_pop(L, 1); | ||
299 | lua_createtable(L, 0, 1); | ||
300 | lua_pushlightuserdata(L, (void *)&KEY_HOOK); | ||
301 | lua_pushvalue(L, -2); | ||
302 | lua_rawset(L, LUA_REGISTRYINDEX); | ||
303 | } | ||
304 | } | ||
305 | |||
306 | |||
307 | static int db_sethook (lua_State *L) { | 296 | static int db_sethook (lua_State *L) { |
308 | int arg, mask, count; | 297 | int arg, mask, count; |
309 | lua_Hook func; | 298 | lua_Hook func; |