diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-09 13:16:06 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-09 13:16:06 -0200 |
| commit | b1379936cf35787d3ef3aab82d1607a3e1562eef (patch) | |
| tree | fe47cb5c35fddab945faf731f0bc175bf5431352 /ldebug.c | |
| parent | 4e0de3a43cc30a83334c272cb7575bf8412bfeae (diff) | |
| download | lua-b1379936cf35787d3ef3aab82d1607a3e1562eef.tar.gz lua-b1379936cf35787d3ef3aab82d1607a3e1562eef.tar.bz2 lua-b1379936cf35787d3ef3aab82d1607a3e1562eef.zip | |
vararg back to '...' (but with another implementation)
new implementation should have zero overhead for non-vararg functions
Diffstat (limited to 'ldebug.c')
| -rw-r--r-- | ldebug.c | 26 |
1 files changed, 21 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.152 2018/01/10 12:02:35 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.153 2018/02/06 19:16:56 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 | */ |
| @@ -187,12 +187,28 @@ static const char *upvalname (Proto *p, int uv) { | |||
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | 189 | ||
| 190 | static const char *findvararg (CallInfo *ci, int n, StkId *pos) { | ||
| 191 | if (clLvalue(s2v(ci->func))->p->is_vararg) { | ||
| 192 | int nextra = ci->u.l.nextraargs; | ||
| 193 | if (n <= nextra) { | ||
| 194 | *pos = ci->func - nextra + (n - 1); | ||
| 195 | return "(*vararg)"; /* generic name for any vararg */ | ||
| 196 | } | ||
| 197 | } | ||
| 198 | return NULL; /* no such vararg */ | ||
| 199 | } | ||
| 200 | |||
| 201 | |||
| 190 | static const char *findlocal (lua_State *L, CallInfo *ci, int n, | 202 | static const char *findlocal (lua_State *L, CallInfo *ci, int n, |
| 191 | StkId *pos) { | 203 | StkId *pos) { |
| 192 | StkId base = ci->func + 1; | 204 | StkId base = ci->func + 1; |
| 193 | const char *name = (isLua(ci)) | 205 | const char *name = NULL; |
| 194 | ? luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci)) | 206 | if (isLua(ci)) { |
| 195 | : NULL; | 207 | if (n < 0) /* access to vararg values? */ |
| 208 | return findvararg(ci, -n, pos); | ||
| 209 | else | ||
| 210 | name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci)); | ||
| 211 | } | ||
| 196 | if (name == NULL) { /* no 'standard' name? */ | 212 | if (name == NULL) { /* no 'standard' name? */ |
| 197 | StkId limit = (ci == L->ci) ? L->top : ci->next->func; | 213 | StkId limit = (ci == L->ci) ? L->top : ci->next->func; |
| 198 | if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */ | 214 | if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */ |
| @@ -324,7 +340,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, | |||
| 324 | } | 340 | } |
| 325 | else { | 341 | else { |
| 326 | ar->isvararg = f->l.p->is_vararg; | 342 | ar->isvararg = f->l.p->is_vararg; |
| 327 | ar->nparams = f->l.p->numparams + f->l.p->is_vararg; | 343 | ar->nparams = f->l.p->numparams; |
| 328 | } | 344 | } |
| 329 | break; | 345 | break; |
| 330 | } | 346 | } |
