aboutsummaryrefslogtreecommitdiff
path: root/ldblib.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldblib.c')
-rw-r--r--ldblib.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/ldblib.c b/ldblib.c
index 35c47f81..85239d7b 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.130 2011/04/08 19:17:36 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.131 2011/10/24 14:54:05 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*/
@@ -253,14 +253,15 @@ static int db_upvaluejoin (lua_State *L) {
253} 253}
254 254
255 255
256#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY); 256#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)
257 257
258 258
259static void hookf (lua_State *L, lua_Debug *ar) { 259static void hookf (lua_State *L, lua_Debug *ar) {
260 static const char *const hooknames[] = 260 static const char *const hooknames[] =
261 {"call", "return", "line", "count", "tail call"}; 261 {"call", "return", "line", "count", "tail call"};
262 gethooktable(L); 262 gethooktable(L);
263 lua_rawgetp(L, -1, L); 263 lua_pushthread(L);
264 lua_rawget(L, -2);
264 if (lua_isfunction(L, -1)) { 265 if (lua_isfunction(L, -1)) {
265 lua_pushstring(L, hooknames[(int)ar->event]); 266 lua_pushstring(L, hooknames[(int)ar->event]);
266 if (ar->currentline >= 0) 267 if (ar->currentline >= 0)
@@ -306,10 +307,15 @@ static int db_sethook (lua_State *L) {
306 count = luaL_optint(L, arg+3, 0); 307 count = luaL_optint(L, arg+3, 0);
307 func = hookf; mask = makemask(smask, count); 308 func = hookf; mask = makemask(smask, count);
308 } 309 }
309 gethooktable(L); 310 if (gethooktable(L) == 0) { /* creating hook table? */
311 lua_pushstring(L, "k");
312 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
313 lua_pushvalue(L, -1);
314 lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
315 }
316 lua_pushthread(L1); lua_xmove(L1, L, 1);
310 lua_pushvalue(L, arg+1); 317 lua_pushvalue(L, arg+1);
311 lua_rawsetp(L, -2, L1); /* set new hook */ 318 lua_rawset(L, -3); /* set new hook */
312 lua_pop(L, 1); /* remove hook table */
313 lua_sethook(L1, func, mask, count); /* set hooks */ 319 lua_sethook(L1, func, mask, count); /* set hooks */
314 return 0; 320 return 0;
315} 321}
@@ -325,7 +331,8 @@ static int db_gethook (lua_State *L) {
325 lua_pushliteral(L, "external hook"); 331 lua_pushliteral(L, "external hook");
326 else { 332 else {
327 gethooktable(L); 333 gethooktable(L);
328 lua_rawgetp(L, -1, L1); /* get hook */ 334 lua_pushthread(L1); lua_xmove(L1, L, 1);
335 lua_rawget(L, -2); /* get hook */
329 lua_remove(L, -2); /* remove hook table */ 336 lua_remove(L, -2); /* remove hook table */
330 } 337 }
331 lua_pushstring(L, unmakemask(mask, buff)); 338 lua_pushstring(L, unmakemask(mask, buff));