diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-11-05 15:26:00 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-11-05 15:26:00 -0200 |
| commit | b7d5f18d71f691df752e220f844ea613a8f6d722 (patch) | |
| tree | 9f9ba3cd43799389c1564be16b7836e09fcf7317 /ldblib.c | |
| parent | 5598b2bc558ba0c755068f21e786d3a6d59eb1ca (diff) | |
| download | lua-b7d5f18d71f691df752e220f844ea613a8f6d722.tar.gz lua-b7d5f18d71f691df752e220f844ea613a8f6d722.tar.bz2 lua-b7d5f18d71f691df752e220f844ea613a8f6d722.zip | |
api functions to manipulate upvalues do not need to check their
arguments (the caller must check them before calling)
Diffstat (limited to 'ldblib.c')
| -rw-r--r-- | ldblib.c | 24 |
1 files changed, 10 insertions, 14 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.112 2009/09/09 20:32:19 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.113 2009/11/05 16:48:31 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,23 +199,10 @@ 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) { | 202 | static int checkupval (lua_State *L, int argf, int argnup) { |
| 214 | lua_Debug ar; | 203 | lua_Debug ar; |
| 215 | int nup = luaL_checkint(L, argnup); | 204 | int nup = luaL_checkint(L, argnup); |
| 216 | luaL_checktype(L, argf, LUA_TFUNCTION); | 205 | 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); | 206 | lua_pushvalue(L, argf); |
| 220 | lua_getinfo(L, ">u", &ar); | 207 | lua_getinfo(L, ">u", &ar); |
| 221 | luaL_argcheck(L, 1 <= nup && nup <= ar.nups, argnup, "invalid upvalue index"); | 208 | luaL_argcheck(L, 1 <= nup && nup <= ar.nups, argnup, "invalid upvalue index"); |
| @@ -223,9 +210,18 @@ static int checkupval (lua_State *L, int argf, int argnup) { | |||
| 223 | } | 210 | } |
| 224 | 211 | ||
| 225 | 212 | ||
| 213 | static int db_upvaladdr (lua_State *L) { | ||
| 214 | int n = checkupval(L, 1, 2); | ||
| 215 | lua_pushlightuserdata(L, lua_upvaladdr(L, 1, n)); | ||
| 216 | return 1; | ||
| 217 | } | ||
| 218 | |||
| 219 | |||
| 226 | static int db_joinupval (lua_State *L) { | 220 | static int db_joinupval (lua_State *L) { |
| 227 | int n1 = checkupval(L, 1, 2); | 221 | int n1 = checkupval(L, 1, 2); |
| 228 | int n2 = checkupval(L, 3, 4); | 222 | int n2 = checkupval(L, 3, 4); |
| 223 | luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected"); | ||
| 224 | luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected"); | ||
| 229 | lua_upvaljoin(L, 1, n1, 3, n2); | 225 | lua_upvaljoin(L, 1, n1, 3, n2); |
| 230 | return 0; | 226 | return 0; |
| 231 | } | 227 | } |
