diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-26 17:04:22 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-26 17:04:22 -0200 |
commit | 563b1f570400828dafa76bfae4a3b0b1eb9721a7 (patch) | |
tree | c78360aaa2c1e9bcabf876d6361ff5d506a04361 | |
parent | 4670476584dd70c002b6a82c700d10cd6d3eb9ba (diff) | |
download | lua-563b1f570400828dafa76bfae4a3b0b1eb9721a7.tar.gz lua-563b1f570400828dafa76bfae4a3b0b1eb9721a7.tar.bz2 lua-563b1f570400828dafa76bfae4a3b0b1eb9721a7.zip |
new way to ensure uniqueness of registry keys
-rw-r--r-- | ldblib.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.24 2000/10/24 19:12:06 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.25 2000/10/26 18:44:26 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,13 +110,15 @@ static int setlocal (lua_State *L) { | |||
110 | 110 | ||
111 | 111 | ||
112 | 112 | ||
113 | #define KEY_CALLHOOK "lua.dblib.callhook" | 113 | /* dummy variables (to define unique addresses) */ |
114 | #define KEY_LINEHOOK "lua.dblib.linehook" | 114 | static char key1, key2; |
115 | #define KEY_CALLHOOK (&key1) | ||
116 | #define KEY_LINEHOOK (&key2) | ||
115 | 117 | ||
116 | 118 | ||
117 | static void hookf (lua_State *L, const char *key) { | 119 | static void hookf (lua_State *L, void *key) { |
118 | lua_getregistry(L); | 120 | lua_getregistry(L); |
119 | lua_pushstring(L, key); | 121 | lua_pushuserdata(L, key); |
120 | lua_gettable(L, -2); | 122 | lua_gettable(L, -2); |
121 | if (lua_isfunction(L, -1)) { | 123 | if (lua_isfunction(L, -1)) { |
122 | lua_pushvalue(L, 1); | 124 | lua_pushvalue(L, 1); |
@@ -140,11 +142,11 @@ static void linef (lua_State *L, lua_Debug *ar) { | |||
140 | } | 142 | } |
141 | 143 | ||
142 | 144 | ||
143 | static void sethook (lua_State *L, const char *key, lua_Hook hook, | 145 | static void sethook (lua_State *L, void *key, lua_Hook hook, |
144 | lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { | 146 | lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { |
145 | lua_settop(L, 1); | 147 | lua_settop(L, 1); |
146 | lua_getregistry(L); | 148 | lua_getregistry(L); |
147 | lua_pushstring(L, key); | 149 | lua_pushuserdata(L, key); |
148 | if (lua_isnil(L, 1)) | 150 | if (lua_isnil(L, 1)) |
149 | (*sethookf)(L, NULL); | 151 | (*sethookf)(L, NULL); |
150 | else if (lua_isfunction(L, 1)) | 152 | else if (lua_isfunction(L, 1)) |