aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-26 17:04:22 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-26 17:04:22 -0200
commit563b1f570400828dafa76bfae4a3b0b1eb9721a7 (patch)
treec78360aaa2c1e9bcabf876d6361ff5d506a04361
parent4670476584dd70c002b6a82c700d10cd6d3eb9ba (diff)
downloadlua-563b1f570400828dafa76bfae4a3b0b1eb9721a7.tar.gz
lua-563b1f570400828dafa76bfae4a3b0b1eb9721a7.tar.bz2
lua-563b1f570400828dafa76bfae4a3b0b1eb9721a7.zip
new way to ensure uniqueness of registry keys
-rw-r--r--ldblib.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/ldblib.c b/ldblib.c
index e133fac3..02dca507 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -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" 114static char key1, key2;
115#define KEY_CALLHOOK (&key1)
116#define KEY_LINEHOOK (&key2)
115 117
116 118
117static void hookf (lua_State *L, const char *key) { 119static 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
143static void sethook (lua_State *L, const char *key, lua_Hook hook, 145static 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))