diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-10-17 19:12:57 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-10-17 19:12:57 -0200 |
commit | 1e81da51bab87148981486a84b846399050f4ef2 (patch) | |
tree | d2c94326ca096e032d1ae3fa75a5d0605f494cc6 /ldblib.c | |
parent | 7cd37142f404462634a5049a840f572e85c5762b (diff) | |
download | lua-1e81da51bab87148981486a84b846399050f4ef2.tar.gz lua-1e81da51bab87148981486a84b846399050f4ef2.tar.bz2 lua-1e81da51bab87148981486a84b846399050f4ef2.zip |
new API for registry and C upvalues + new implementation for references
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 16 |
1 files changed, 6 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.37 2001/06/06 18:00:19 roberto Exp $ | 2 | ** $Id: ldblib.c,v 1.38 2001/08/31 19:46:07 roberto Exp $ |
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 | */ |
@@ -116,16 +116,14 @@ static int setlocal (lua_State *L) { | |||
116 | 116 | ||
117 | 117 | ||
118 | static void hookf (lua_State *L, const l_char *key) { | 118 | static void hookf (lua_State *L, const l_char *key) { |
119 | lua_getregistry(L); | ||
120 | lua_pushstring(L, key); | 119 | lua_pushstring(L, key); |
121 | lua_gettable(L, -2); | 120 | lua_gettable(L, LUA_REGISTRYINDEX); |
122 | if (lua_isfunction(L, -1)) { | 121 | if (lua_isfunction(L, -1)) { |
123 | lua_pushvalue(L, -3); /* original argument (below table and function) */ | 122 | lua_pushvalue(L, -2); /* original argument (below function) */ |
124 | lua_rawcall(L, 1, 0); | 123 | lua_rawcall(L, 1, 0); |
125 | } | 124 | } |
126 | else | 125 | else |
127 | lua_pop(L, 1); /* pop result from gettable */ | 126 | lua_pop(L, 1); /* pop result from gettable */ |
128 | lua_pop(L, 1); /* pop table */ | ||
129 | } | 127 | } |
130 | 128 | ||
131 | 129 | ||
@@ -150,13 +148,11 @@ static void sethook (lua_State *L, const l_char *key, lua_Hook hook, | |||
150 | (*sethookf)(L, hook); | 148 | (*sethookf)(L, hook); |
151 | else | 149 | else |
152 | luaL_argerror(L, 1, l_s("function expected")); | 150 | luaL_argerror(L, 1, l_s("function expected")); |
153 | lua_getregistry(L); | ||
154 | lua_pushstring(L, key); | 151 | lua_pushstring(L, key); |
155 | lua_pushvalue(L, -1); /* dup key */ | 152 | lua_gettable(L, LUA_REGISTRYINDEX); /* get old value */ |
156 | lua_gettable(L, -3); /* get old value */ | 153 | lua_pushstring(L, key); |
157 | lua_pushvalue(L, -2); /* key (again) */ | ||
158 | lua_pushvalue(L, 1); | 154 | lua_pushvalue(L, 1); |
159 | lua_settable(L, -5); /* set new value */ | 155 | lua_settable(L, LUA_REGISTRYINDEX); /* set new value */ |
160 | } | 156 | } |
161 | 157 | ||
162 | 158 | ||