diff options
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.45 2002/03/27 15:30:41 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.46 2002/04/02 20:41:59 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 | */ |
@@ -110,12 +110,12 @@ static int setlocal (lua_State *L) { | |||
110 | 110 | ||
111 | 111 | ||
112 | 112 | ||
113 | #define KEY_CALLHOOK "luadblibCallhook" | 113 | static const char KEY_CALLHOOK = 'c'; |
114 | #define KEY_LINEHOOK "luadblibLinehook" | 114 | static const char KEY_LINEHOOK = 'l'; |
115 | 115 | ||
116 | 116 | ||
117 | static void hookf (lua_State *L, const char *key) { | 117 | static void hookf (lua_State *L, void *key) { |
118 | lua_pushstring(L, key); | 118 | lua_pushudataval(L, key); |
119 | lua_rawget(L, LUA_REGISTRYINDEX); | 119 | lua_rawget(L, LUA_REGISTRYINDEX); |
120 | if (lua_isfunction(L, -1)) { | 120 | if (lua_isfunction(L, -1)) { |
121 | lua_pushvalue(L, -2); /* original argument (below function) */ | 121 | lua_pushvalue(L, -2); /* original argument (below function) */ |
@@ -128,17 +128,17 @@ static void hookf (lua_State *L, const char *key) { | |||
128 | 128 | ||
129 | static void callf (lua_State *L, lua_Debug *ar) { | 129 | static void callf (lua_State *L, lua_Debug *ar) { |
130 | lua_pushstring(L, ar->event); | 130 | lua_pushstring(L, ar->event); |
131 | hookf(L, KEY_CALLHOOK); | 131 | hookf(L, (void *)&KEY_CALLHOOK); |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
135 | static void linef (lua_State *L, lua_Debug *ar) { | 135 | static void linef (lua_State *L, lua_Debug *ar) { |
136 | lua_pushnumber(L, ar->currentline); | 136 | lua_pushnumber(L, ar->currentline); |
137 | hookf(L, KEY_LINEHOOK); | 137 | hookf(L, (void *)&KEY_LINEHOOK); |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | static void sethook (lua_State *L, const char *key, lua_Hook hook, | 141 | static void sethook (lua_State *L, void *key, lua_Hook hook, |
142 | lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { | 142 | lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { |
143 | lua_settop(L, 1); | 143 | lua_settop(L, 1); |
144 | if (lua_isnoneornil(L, 1)) | 144 | if (lua_isnoneornil(L, 1)) |
@@ -147,22 +147,22 @@ static void sethook (lua_State *L, const char *key, lua_Hook hook, | |||
147 | (*sethookf)(L, hook); | 147 | (*sethookf)(L, hook); |
148 | else | 148 | else |
149 | luaL_argerror(L, 1, "function expected"); | 149 | luaL_argerror(L, 1, "function expected"); |
150 | lua_pushstring(L, key); | 150 | lua_pushudataval(L, key); |
151 | lua_rawget(L, LUA_REGISTRYINDEX); /* get old value */ | 151 | lua_rawget(L, LUA_REGISTRYINDEX); /* get old value */ |
152 | lua_pushstring(L, key); | 152 | lua_pushudataval(L, key); |
153 | lua_pushvalue(L, 1); | 153 | lua_pushvalue(L, 1); |
154 | lua_rawset(L, LUA_REGISTRYINDEX); /* set new value */ | 154 | lua_rawset(L, LUA_REGISTRYINDEX); /* set new value */ |
155 | } | 155 | } |
156 | 156 | ||
157 | 157 | ||
158 | static int setcallhook (lua_State *L) { | 158 | static int setcallhook (lua_State *L) { |
159 | sethook(L, KEY_CALLHOOK, callf, lua_setcallhook); | 159 | sethook(L, (void *)&KEY_CALLHOOK, callf, lua_setcallhook); |
160 | return 1; | 160 | return 1; |
161 | } | 161 | } |
162 | 162 | ||
163 | 163 | ||
164 | static int setlinehook (lua_State *L) { | 164 | static int setlinehook (lua_State *L) { |
165 | sethook(L, KEY_LINEHOOK, linef, lua_setlinehook); | 165 | sethook(L, (void *)&KEY_LINEHOOK, linef, lua_setlinehook); |
166 | return 1; | 166 | return 1; |
167 | } | 167 | } |
168 | 168 | ||