From 43013b39cc28e873e18207e8e7259b6b90fed06b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 18 Nov 2002 09:01:55 -0200 Subject: new representation for hooks (to allow asynchronous calls to sethook) --- ldebug.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'ldebug.c') diff --git a/ldebug.c b/ldebug.c index 91a3fc95..798d7eea 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 1.135 2002/10/16 20:40:58 roberto Exp roberto $ +** $Id: ldebug.c,v 1.136 2002/11/07 15:37:10 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -49,20 +49,29 @@ static int currentline (CallInfo *ci) { } -LUA_API int lua_sethook (lua_State *L, lua_Hook func, unsigned long mask) { - int allow; +void luaG_inithooks (lua_State *L) { CallInfo *ci; - lua_lock(L); - allow = allowhook(L); - if (func == NULL) mask = 0; - else if (mask == 0) func = NULL; - L->hook = func; - L->hookmask = mask; - setallowhook(L, allow); - resethookcount(L); for (ci = L->ci; ci != L->base_ci; ci--) /* update all `savedpc's */ currentpc(ci); - lua_unlock(L); + L->hookinit = 1; +} + + +/* +** this function can be called asynchronous (e.g. during a signal) +*/ +LUA_API int lua_sethook (lua_State *L, lua_Hook func, unsigned long mask) { + ls_count count = lua_getmaskcount(mask); + if (func == NULL || mask == 0) { /* turn off hooks? */ + mask = 0; + func = NULL; + } + else if (count > 0) mask |= (1<hook = func; + L->basehookcount = count; + resethookcount(L); + L->hookmask = cast(lu_byte, mask & 0xf); + L->hookinit = 0; return 1; } @@ -73,7 +82,7 @@ LUA_API lua_Hook lua_gethook (lua_State *L) { LUA_API unsigned long lua_gethookmask (lua_State *L) { - return L->hookmask; + return L->hookmask | LUA_MASKCOUNT(L->basehookcount); } -- cgit v1.2.3-55-g6feb