diff options
Diffstat (limited to 'ldebug.c')
| -rw-r--r-- | ldebug.c | 35 |
1 files changed, 22 insertions, 13 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 1.135 2002/10/16 20:40:58 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.136 2002/11/07 15:37:10 roberto Exp roberto $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -49,20 +49,29 @@ static int currentline (CallInfo *ci) { | |||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | 51 | ||
| 52 | LUA_API int lua_sethook (lua_State *L, lua_Hook func, unsigned long mask) { | 52 | void luaG_inithooks (lua_State *L) { |
| 53 | int allow; | ||
| 54 | CallInfo *ci; | 53 | CallInfo *ci; |
| 55 | lua_lock(L); | ||
| 56 | allow = allowhook(L); | ||
| 57 | if (func == NULL) mask = 0; | ||
| 58 | else if (mask == 0) func = NULL; | ||
| 59 | L->hook = func; | ||
| 60 | L->hookmask = mask; | ||
| 61 | setallowhook(L, allow); | ||
| 62 | resethookcount(L); | ||
| 63 | for (ci = L->ci; ci != L->base_ci; ci--) /* update all `savedpc's */ | 54 | for (ci = L->ci; ci != L->base_ci; ci--) /* update all `savedpc's */ |
| 64 | currentpc(ci); | 55 | currentpc(ci); |
| 65 | lua_unlock(L); | 56 | L->hookinit = 1; |
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | /* | ||
| 61 | ** this function can be called asynchronous (e.g. during a signal) | ||
| 62 | */ | ||
| 63 | LUA_API int lua_sethook (lua_State *L, lua_Hook func, unsigned long mask) { | ||
| 64 | ls_count count = lua_getmaskcount(mask); | ||
| 65 | if (func == NULL || mask == 0) { /* turn off hooks? */ | ||
| 66 | mask = 0; | ||
| 67 | func = NULL; | ||
| 68 | } | ||
| 69 | else if (count > 0) mask |= (1<<LUA_HOOKCOUNT); | ||
| 70 | L->hook = func; | ||
| 71 | L->basehookcount = count; | ||
| 72 | resethookcount(L); | ||
| 73 | L->hookmask = cast(lu_byte, mask & 0xf); | ||
| 74 | L->hookinit = 0; | ||
| 66 | return 1; | 75 | return 1; |
| 67 | } | 76 | } |
| 68 | 77 | ||
| @@ -73,7 +82,7 @@ LUA_API lua_Hook lua_gethook (lua_State *L) { | |||
| 73 | 82 | ||
| 74 | 83 | ||
| 75 | LUA_API unsigned long lua_gethookmask (lua_State *L) { | 84 | LUA_API unsigned long lua_gethookmask (lua_State *L) { |
| 76 | return L->hookmask; | 85 | return L->hookmask | LUA_MASKCOUNT(L->basehookcount); |
| 77 | } | 86 | } |
| 78 | 87 | ||
| 79 | 88 | ||
