diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-06-21 13:30:12 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-06-21 13:30:12 -0300 |
commit | ca3865cf1b1e0195de9d1c71e48305146798cb95 (patch) | |
tree | 7a2e39ad9fff66956365b69c45b2e967080afceb /ldblib.c | |
parent | bef5980744d260246df81a5cf824c43b9b8080f8 (diff) | |
download | lua-ca3865cf1b1e0195de9d1c71e48305146798cb95.tar.gz lua-ca3865cf1b1e0195de9d1c71e48305146798cb95.tar.bz2 lua-ca3865cf1b1e0195de9d1c71e48305146798cb95.zip |
'getlocal' gets information about parameters of Lua functions
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 32 |
1 files changed, 20 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.120 2010/02/18 19:18:41 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.121 2010/03/26 20:58:11 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 | */ |
@@ -157,19 +157,27 @@ static int db_getlocal (lua_State *L) { | |||
157 | lua_State *L1 = getthread(L, &arg); | 157 | lua_State *L1 = getthread(L, &arg); |
158 | lua_Debug ar; | 158 | lua_Debug ar; |
159 | const char *name; | 159 | const char *name; |
160 | if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ | 160 | int nvar = luaL_checkint(L, arg+2); /* local-variable index */ |
161 | return luaL_argerror(L, arg+1, "level out of range"); | 161 | if (lua_isfunction(L, arg + 1)) { /* function argument? */ |
162 | name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2)); | 162 | lua_pushvalue(L, arg + 1); /* push function */ |
163 | if (name) { | 163 | lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */ |
164 | lua_xmove(L1, L, 1); | ||
165 | lua_pushstring(L, name); | ||
166 | lua_pushvalue(L, -2); | ||
167 | return 2; | ||
168 | } | ||
169 | else { | ||
170 | lua_pushnil(L); | ||
171 | return 1; | 164 | return 1; |
172 | } | 165 | } |
166 | else { /* stack-level argument */ | ||
167 | if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ | ||
168 | return luaL_argerror(L, arg+1, "level out of range"); | ||
169 | name = lua_getlocal(L1, &ar, nvar); | ||
170 | if (name) { | ||
171 | lua_xmove(L1, L, 1); /* push local value */ | ||
172 | lua_pushstring(L, name); /* push name */ | ||
173 | lua_pushvalue(L, -2); /* re-order */ | ||
174 | return 2; | ||
175 | } | ||
176 | else { | ||
177 | lua_pushnil(L); /* no name (nor value) */ | ||
178 | return 1; | ||
179 | } | ||
180 | } | ||
173 | } | 181 | } |
174 | 182 | ||
175 | 183 | ||