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 /ldebug.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 'ldebug.c')
| -rw-r--r-- | ldebug.c | 21 |
1 files changed, 15 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.70 2010/04/13 20:48:12 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.71 2010/06/16 13:44:36 roberto Exp roberto $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -119,12 +119,21 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n, | |||
| 119 | 119 | ||
| 120 | 120 | ||
| 121 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | 121 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { |
| 122 | StkId pos; | 122 | const char *name; |
| 123 | const char *name = findlocal(L, ar->i_ci, n, &pos); | ||
| 124 | lua_lock(L); | 123 | lua_lock(L); |
| 125 | if (name) { | 124 | if (ar == NULL) { /* information about non-active function? */ |
| 126 | setobj2s(L, L->top, pos); | 125 | if (!isLfunction(L->top - 1)) /* not a Lua function? */ |
| 127 | api_incr_top(L); | 126 | name = NULL; |
| 127 | else /* consider live variables at function start (parameters) */ | ||
| 128 | name = luaF_getlocalname(clvalue(L->top - 1)->l.p, n, 0); | ||
| 129 | } | ||
| 130 | else { /* active function; get information through 'ar' */ | ||
| 131 | StkId pos; | ||
| 132 | name = findlocal(L, ar->i_ci, n, &pos); | ||
| 133 | if (name) { | ||
| 134 | setobj2s(L, L->top, pos); | ||
| 135 | api_incr_top(L); | ||
| 136 | } | ||
| 128 | } | 137 | } |
| 129 | lua_unlock(L); | 138 | lua_unlock(L); |
| 130 | return name; | 139 | return name; |
