aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-11-06 15:58:38 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-11-06 15:58:38 -0200
commit40a4c767739f70645ea71bbf6330f4ad5e48ca55 (patch)
tree775d640fa7b50ae830c897f3d3261a571a53c2f2
parent1385d81d201620f7e72b707ff4f306c1147cf9d6 (diff)
downloadlua-40a4c767739f70645ea71bbf6330f4ad5e48ca55.tar.gz
lua-40a4c767739f70645ea71bbf6330f4ad5e48ca55.tar.bz2
lua-40a4c767739f70645ea71bbf6330f4ad5e48ca55.zip
setlinehook/setcallhook return old hook
-rw-r--r--ldblib.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/ldblib.c b/ldblib.c
index 6e8d6b59..aa00701f 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.27 2000/10/27 16:15:53 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.28 2000/11/06 13:19:08 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*/
@@ -145,28 +145,31 @@ static void linef (lua_State *L, lua_Debug *ar) {
145static void sethook (lua_State *L, void *key, lua_Hook hook, 145static void sethook (lua_State *L, void *key, lua_Hook hook,
146 lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { 146 lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) {
147 lua_settop(L, 1); 147 lua_settop(L, 1);
148 lua_getregistry(L);
149 lua_pushuserdata(L, key);
150 if (lua_isnil(L, 1)) 148 if (lua_isnil(L, 1))
151 (*sethookf)(L, NULL); 149 (*sethookf)(L, NULL);
152 else if (lua_isfunction(L, 1)) 150 else if (lua_isfunction(L, 1))
153 (*sethookf)(L, hook); 151 (*sethookf)(L, hook);
154 else 152 else
155 luaL_argerror(L, 1, "function expected"); 153 luaL_argerror(L, 1, "function expected");
154 lua_getregistry(L);
155 lua_pushuserdata(L, key);
156 lua_pushvalue(L, -1); /* dup key */
157 lua_gettable(L, -3); /* get old value */
158 lua_pushvalue(L, -2); /* key (again) */
156 lua_pushvalue(L, 1); 159 lua_pushvalue(L, 1);
157 lua_settable(L, -3); 160 lua_settable(L, -5); /* set new value */
158} 161}
159 162
160 163
161static int setcallhook (lua_State *L) { 164static int setcallhook (lua_State *L) {
162 sethook(L, KEY_CALLHOOK, callf, lua_setcallhook); 165 sethook(L, KEY_CALLHOOK, callf, lua_setcallhook);
163 return 0; 166 return 1;
164} 167}
165 168
166 169
167static int setlinehook (lua_State *L) { 170static int setlinehook (lua_State *L) {
168 sethook(L, KEY_LINEHOOK, linef, lua_setlinehook); 171 sethook(L, KEY_LINEHOOK, linef, lua_setlinehook);
169 return 0; 172 return 1;
170} 173}
171 174
172 175