aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/ldebug.c b/ldebug.c
index 56f6c820..0108b47e 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.125 2002/07/16 14:26:56 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.126 2002/08/05 14:51:21 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*/
@@ -35,7 +35,7 @@ static int isLua (CallInfo *ci) {
35 35
36static int currentpc (lua_State *L, CallInfo *ci) { 36static int currentpc (lua_State *L, CallInfo *ci) {
37 if (!isLua(ci)) return -1; /* function is not a Lua function? */ 37 if (!isLua(ci)) return -1; /* function is not a Lua function? */
38 if (ci->pc && ci->pc != &luaV_callingmark) 38 if (ci->pc != &luaV_callingmark) /* is not calling another Lua function? */
39 ci->u.l.savedpc = *ci->pc; /* `pc' may not be saved; save it */ 39 ci->u.l.savedpc = *ci->pc; /* `pc' may not be saved; save it */
40 /* function's pc is saved */ 40 /* function's pc is saved */
41 return pcRel(ci->u.l.savedpc, ci_func(ci)->l.p); 41 return pcRel(ci->u.l.savedpc, ci_func(ci)->l.p);
@@ -51,19 +51,9 @@ static int currentline (lua_State *L, CallInfo *ci) {
51} 51}
52 52
53 53
54/*
55** save all `pc's from active Lua functions
56*/
57void luaG_saveallpcs (lua_State *L) {
58 CallInfo *ci;
59 /* first save all not saved `pc's */
60 for (ci = L->ci; ci != L->base_ci; ci--)
61 currentpc(L, ci); /* save `pc', if necessary */
62}
63
64
65LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask) { 54LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask) {
66 int allow; 55 int allow;
56 CallInfo *ci;
67 lua_lock(L); 57 lua_lock(L);
68 allow = allowhook(L); 58 allow = allowhook(L);
69 if (func == NULL) mask = 0; 59 if (func == NULL) mask = 0;
@@ -72,7 +62,8 @@ LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask) {
72 L->hookmask = mask; 62 L->hookmask = mask;
73 setallowhook(L, allow); 63 setallowhook(L, allow);
74 resethookcount(L); 64 resethookcount(L);
75 luaG_saveallpcs(L); 65 for (ci = L->ci; ci != L->base_ci; ci--) /* update all `savedpc's */
66 currentpc(L, ci);
76 lua_unlock(L); 67 lua_unlock(L);
77 return 1; 68 return 1;
78} 69}
@@ -547,6 +538,14 @@ static void addinfo (lua_State *L, int internal) {
547void luaG_errormsg (lua_State *L, int internal) { 538void luaG_errormsg (lua_State *L, int internal) {
548 if (ttisstring(L->top - 1)) 539 if (ttisstring(L->top - 1))
549 addinfo(L, internal); 540 addinfo(L, internal);
541 if (L->errfunc != 0) { /* is there an error handling function? */
542 StkId errfunc = restorestack(L, L->errfunc);
543 if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
544 setobj(L->top, L->top - 1); /* move argument */
545 setobj(L->top - 1, errfunc); /* push function */
546 incr_top(L);
547 luaD_call(L, L->top - 2, 1); /* call it */
548 }
550 luaD_throw(L, LUA_ERRRUN); 549 luaD_throw(L, LUA_ERRRUN);
551} 550}
552 551