diff options
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.111 2009/08/04 18:27:57 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.112 2009/09/09 20:32:19 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 | */ |
@@ -199,6 +199,37 @@ static int db_setupvalue (lua_State *L) { | |||
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | static int db_upvaladdr (lua_State *L) { | ||
203 | void *addr; | ||
204 | int n = luaL_checkint(L, 2); | ||
205 | luaL_checktype(L, 1, LUA_TFUNCTION); | ||
206 | addr = lua_upvaladdr(L, 1, n); | ||
207 | if (addr == NULL) lua_pushnil(L); | ||
208 | else lua_pushlightuserdata(L, addr); | ||
209 | return 1; | ||
210 | } | ||
211 | |||
212 | |||
213 | static int checkupval (lua_State *L, int argf, int argnup) { | ||
214 | lua_Debug ar; | ||
215 | int nup = luaL_checkint(L, argnup); | ||
216 | luaL_checktype(L, argf, LUA_TFUNCTION); | ||
217 | luaL_argcheck(L, !lua_iscfunction(L, argf), argf, | ||
218 | "cannot join upvalues of a C function"); | ||
219 | lua_pushvalue(L, argf); | ||
220 | lua_getinfo(L, ">u", &ar); | ||
221 | luaL_argcheck(L, 1 <= nup && nup <= ar.nups, argnup, "invalid upvalue index"); | ||
222 | return nup; | ||
223 | } | ||
224 | |||
225 | |||
226 | static int db_joinupval (lua_State *L) { | ||
227 | int n1 = checkupval(L, 1, 2); | ||
228 | int n2 = checkupval(L, 3, 4); | ||
229 | lua_upvaljoin(L, 1, n1, 3, n2); | ||
230 | return 0; | ||
231 | } | ||
232 | |||
202 | 233 | ||
203 | static const char KEY_HOOK = 'h'; | 234 | static const char KEY_HOOK = 'h'; |
204 | 235 | ||
@@ -338,6 +369,8 @@ static const luaL_Reg dblib[] = { | |||
338 | {"getregistry", db_getregistry}, | 369 | {"getregistry", db_getregistry}, |
339 | {"getmetatable", db_getmetatable}, | 370 | {"getmetatable", db_getmetatable}, |
340 | {"getupvalue", db_getupvalue}, | 371 | {"getupvalue", db_getupvalue}, |
372 | {"joinupval", db_joinupval}, | ||
373 | {"upvaladdr", db_upvaladdr}, | ||
341 | {"setfenv", db_setfenv}, | 374 | {"setfenv", db_setfenv}, |
342 | {"sethook", db_sethook}, | 375 | {"sethook", db_sethook}, |
343 | {"setlocal", db_setlocal}, | 376 | {"setlocal", db_setlocal}, |