diff options
Diffstat (limited to '')
| -rw-r--r-- | ldblib.c | 15 |
1 files changed, 9 insertions, 6 deletions
| @@ -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) { | |||
| 145 | static void sethook (lua_State *L, void *key, lua_Hook hook, | 145 | static 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 | ||
| 161 | static int setcallhook (lua_State *L) { | 164 | static 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 | ||
| 167 | static int setlinehook (lua_State *L) { | 170 | static 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 | ||
