diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-18 09:01:55 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-18 09:01:55 -0200 |
commit | 43013b39cc28e873e18207e8e7259b6b90fed06b (patch) | |
tree | 3c2a9c520a01086df28c8f0d1ef6d9b5069fa451 /ldo.c | |
parent | 94912d99fcdf61c1fc6dc8897c9d2b0e042e0d63 (diff) | |
download | lua-43013b39cc28e873e18207e8e7259b6b90fed06b.tar.gz lua-43013b39cc28e873e18207e8e7259b6b90fed06b.tar.bz2 lua-43013b39cc28e873e18207e8e7259b6b90fed06b.zip |
new representation for hooks (to allow asynchronous calls to sethook)
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.200 2002/11/13 11:31:39 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.201 2002/11/14 16:15:53 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -154,7 +154,7 @@ static void luaD_growCI (lua_State *L) { | |||
154 | 154 | ||
155 | void luaD_callhook (lua_State *L, int event, int line) { | 155 | void luaD_callhook (lua_State *L, int event, int line) { |
156 | lua_Hook hook = L->hook; | 156 | lua_Hook hook = L->hook; |
157 | if (hook && allowhook(L)) { | 157 | if (hook && L->allowhook) { |
158 | ptrdiff_t top = savestack(L, L->top); | 158 | ptrdiff_t top = savestack(L, L->top); |
159 | ptrdiff_t ci_top = savestack(L, L->ci->top); | 159 | ptrdiff_t ci_top = savestack(L, L->ci->top); |
160 | lua_Debug ar; | 160 | lua_Debug ar; |
@@ -163,12 +163,12 @@ void luaD_callhook (lua_State *L, int event, int line) { | |||
163 | ar.i_ci = L->ci - L->base_ci; | 163 | ar.i_ci = L->ci - L->base_ci; |
164 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 164 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
165 | L->ci->top = L->top + LUA_MINSTACK; | 165 | L->ci->top = L->top + LUA_MINSTACK; |
166 | setallowhook(L, 0); /* cannot call hooks inside a hook */ | 166 | L->allowhook = 0; /* cannot call hooks inside a hook */ |
167 | lua_unlock(L); | 167 | lua_unlock(L); |
168 | (*hook)(L, &ar); | 168 | (*hook)(L, &ar); |
169 | lua_lock(L); | 169 | lua_lock(L); |
170 | lua_assert(!allowhook(L)); | 170 | lua_assert(!L->allowhook); |
171 | setallowhook(L, 1); | 171 | L->allowhook = 1; |
172 | L->ci->top = restorestack(L, ci_top); | 172 | L->ci->top = restorestack(L, ci_top); |
173 | L->top = restorestack(L, top); | 173 | L->top = restorestack(L, top); |
174 | } | 174 | } |
@@ -328,16 +328,16 @@ static void resume (lua_State *L, void *ud) { | |||
328 | 328 | ||
329 | LUA_API int lua_resume (lua_State *L, int nargs) { | 329 | LUA_API int lua_resume (lua_State *L, int nargs) { |
330 | int status; | 330 | int status; |
331 | int old_allowhooks; | 331 | lu_byte old_allowhooks; |
332 | lua_lock(L); | 332 | lua_lock(L); |
333 | old_allowhooks = allowhook(L); | 333 | old_allowhooks = L->allowhook; |
334 | lua_assert(L->errfunc == 0); | 334 | lua_assert(L->errfunc == 0); |
335 | status = luaD_rawrunprotected(L, resume, &nargs); | 335 | status = luaD_rawrunprotected(L, resume, &nargs); |
336 | if (status != 0) { /* error? */ | 336 | if (status != 0) { /* error? */ |
337 | L->ci = L->base_ci; /* go back to initial level */ | 337 | L->ci = L->base_ci; /* go back to initial level */ |
338 | luaF_close(L, L->ci->base); /* close eventual pending closures */ | 338 | luaF_close(L, L->ci->base); /* close eventual pending closures */ |
339 | seterrorobj(L, status, L->ci->base); | 339 | seterrorobj(L, status, L->ci->base); |
340 | setallowhook(L, old_allowhooks); | 340 | L->allowhook = old_allowhooks; |
341 | restore_stack_limit(L); | 341 | restore_stack_limit(L); |
342 | } | 342 | } |
343 | lua_unlock(L); | 343 | lua_unlock(L); |
@@ -383,7 +383,7 @@ int luaD_pcall (lua_State *L, int nargs, int nresults, ptrdiff_t errfunc) { | |||
383 | int status; | 383 | int status; |
384 | ptrdiff_t old_top = savestack(L, L->top); | 384 | ptrdiff_t old_top = savestack(L, L->top); |
385 | ptrdiff_t old_ci = saveci(L, L->ci); | 385 | ptrdiff_t old_ci = saveci(L, L->ci); |
386 | int old_allowhooks = allowhook(L); | 386 | lu_byte old_allowhooks = L->allowhook; |
387 | ptrdiff_t old_errfunc = L->errfunc; | 387 | ptrdiff_t old_errfunc = L->errfunc; |
388 | L->errfunc = errfunc; | 388 | L->errfunc = errfunc; |
389 | c.func = L->top - (nargs+1); /* function to be called */ | 389 | c.func = L->top - (nargs+1); /* function to be called */ |
@@ -394,7 +394,7 @@ int luaD_pcall (lua_State *L, int nargs, int nresults, ptrdiff_t errfunc) { | |||
394 | luaF_close(L, oldtop); /* close eventual pending closures */ | 394 | luaF_close(L, oldtop); /* close eventual pending closures */ |
395 | seterrorobj(L, status, oldtop); | 395 | seterrorobj(L, status, oldtop); |
396 | L->ci = restoreci(L, old_ci); | 396 | L->ci = restoreci(L, old_ci); |
397 | setallowhook(L, old_allowhooks); | 397 | L->allowhook = old_allowhooks; |
398 | restore_stack_limit(L); | 398 | restore_stack_limit(L); |
399 | } | 399 | } |
400 | L->errfunc = old_errfunc; | 400 | L->errfunc = old_errfunc; |