diff options
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 38 |
1 files changed, 17 insertions, 21 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.7 1999/11/22 13:12:07 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.8 1999/11/22 17:39:51 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 | */ |
@@ -144,32 +144,28 @@ static void setlocal (lua_State *L) { | |||
144 | 144 | ||
145 | 145 | ||
146 | 146 | ||
147 | static int linehook = -1; /* Lua reference to line hook function */ | 147 | static int linehook = LUA_NOREF; /* Lua reference to line hook function */ |
148 | static int callhook = -1; /* Lua reference to call hook function */ | 148 | static int callhook = LUA_NOREF; /* Lua reference to call hook function */ |
149 | 149 | ||
150 | 150 | ||
151 | static void dohook (lua_State *L, int ref) { | ||
152 | lua_LHFunction oldlinehook = lua_setlinehook(L, NULL); | ||
153 | lua_CHFunction oldcallhook = lua_setcallhook(L, NULL); | ||
154 | lua_callfunction(L, lua_getref(L, ref)); | ||
155 | lua_setlinehook(L, oldlinehook); | ||
156 | lua_setcallhook(L, oldcallhook); | ||
157 | } | ||
158 | |||
159 | 151 | ||
160 | static void linef (lua_State *L, int line) { | 152 | static void linef (lua_State *L, int line) { |
161 | lua_pushnumber(L, line); | 153 | if (linehook != LUA_NOREF) { |
162 | dohook(L, linehook); | 154 | lua_pushnumber(L, line); |
155 | lua_callfunction(L, lua_getref(L, linehook)); | ||
156 | } | ||
163 | } | 157 | } |
164 | 158 | ||
165 | 159 | ||
166 | static void callf (lua_State *L, lua_Function func, const char *file, int line) { | 160 | static void callf (lua_State *L, lua_Function f, const char *file, int line) { |
167 | if (func != LUA_NOOBJECT) { | 161 | if (callhook != LUA_NOREF) { |
168 | lua_pushobject(L, func); | 162 | if (f != LUA_NOOBJECT) { |
169 | lua_pushstring(L, file); | 163 | lua_pushobject(L, f); |
170 | lua_pushnumber(L, line); | 164 | lua_pushstring(L, file); |
165 | lua_pushnumber(L, line); | ||
166 | } | ||
167 | lua_callfunction(L, lua_getref(L, callhook)); | ||
171 | } | 168 | } |
172 | dohook(L, callhook); | ||
173 | } | 169 | } |
174 | 170 | ||
175 | 171 | ||
@@ -177,7 +173,7 @@ static void setcallhook (lua_State *L) { | |||
177 | lua_Object f = lua_getparam(L, 1); | 173 | lua_Object f = lua_getparam(L, 1); |
178 | lua_unref(L, callhook); | 174 | lua_unref(L, callhook); |
179 | if (f == LUA_NOOBJECT) { | 175 | if (f == LUA_NOOBJECT) { |
180 | callhook = -1; | 176 | callhook = LUA_NOREF; |
181 | lua_setcallhook(L, NULL); | 177 | lua_setcallhook(L, NULL); |
182 | } | 178 | } |
183 | else { | 179 | else { |
@@ -192,7 +188,7 @@ static void setlinehook (lua_State *L) { | |||
192 | lua_Object f = lua_getparam(L, 1); | 188 | lua_Object f = lua_getparam(L, 1); |
193 | lua_unref(L, linehook); | 189 | lua_unref(L, linehook); |
194 | if (f == LUA_NOOBJECT) { | 190 | if (f == LUA_NOOBJECT) { |
195 | linehook = -1; | 191 | linehook = LUA_NOREF; |
196 | lua_setlinehook(L, NULL); | 192 | lua_setlinehook(L, NULL); |
197 | } | 193 | } |
198 | else { | 194 | else { |