diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-14 12:13:48 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-14 12:13:48 -0300 |
| commit | 7dfa4cd655118faf164427356609fec31906dac2 (patch) | |
| tree | d39fac9afba1dc0ab01dd5d174824120650c9eab /ldebug.c | |
| parent | fc6203ee4308173283f9ad9de6694d47f0908c4d (diff) | |
| download | lua-7dfa4cd655118faf164427356609fec31906dac2.tar.gz lua-7dfa4cd655118faf164427356609fec31906dac2.tar.bz2 lua-7dfa4cd655118faf164427356609fec31906dac2.zip | |
first implementation of light C functions
Diffstat (limited to 'ldebug.c')
| -rw-r--r-- | ldebug.c | 32 |
1 files changed, 17 insertions, 15 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.68 2010/04/05 16:26:37 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.69 2010/04/08 17:06:33 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 | */ |
| @@ -144,7 +144,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
| 144 | 144 | ||
| 145 | 145 | ||
| 146 | static void funcinfo (lua_Debug *ar, Closure *cl) { | 146 | static void funcinfo (lua_Debug *ar, Closure *cl) { |
| 147 | if (cl->c.isC) { | 147 | if (cl == NULL || cl->c.isC) { |
| 148 | ar->source = "=[C]"; | 148 | ar->source = "=[C]"; |
| 149 | ar->linedefined = -1; | 149 | ar->linedefined = -1; |
| 150 | ar->lastlinedefined = -1; | 150 | ar->lastlinedefined = -1; |
| @@ -191,8 +191,8 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, | |||
| 191 | break; | 191 | break; |
| 192 | } | 192 | } |
| 193 | case 'u': { | 193 | case 'u': { |
| 194 | ar->nups = f->c.nupvalues; | 194 | ar->nups = (f == NULL) ? 0 : f->c.nupvalues; |
| 195 | if (f->c.isC) { | 195 | if (f == NULL || f->c.isC) { |
| 196 | ar->isvararg = 1; | 196 | ar->isvararg = 1; |
| 197 | ar->nparams = 0; | 197 | ar->nparams = 0; |
| 198 | } | 198 | } |
| @@ -226,28 +226,30 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, | |||
| 226 | 226 | ||
| 227 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | 227 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { |
| 228 | int status; | 228 | int status; |
| 229 | Closure *f = NULL; | 229 | Closure *cl; |
| 230 | CallInfo *ci = NULL; | 230 | CallInfo *ci; |
| 231 | StkId func; | ||
| 231 | lua_lock(L); | 232 | lua_lock(L); |
| 232 | if (*what == '>') { | 233 | if (*what == '>') { |
| 233 | StkId func = L->top - 1; | 234 | ci = NULL; |
| 235 | func = L->top - 1; | ||
| 234 | luai_apicheck(L, ttisfunction(func)); | 236 | luai_apicheck(L, ttisfunction(func)); |
| 235 | what++; /* skip the '>' */ | 237 | what++; /* skip the '>' */ |
| 236 | f = clvalue(func); | ||
| 237 | L->top--; /* pop function */ | 238 | L->top--; /* pop function */ |
| 238 | } | 239 | } |
| 239 | else { | 240 | else { |
| 240 | ci = ar->i_ci; | 241 | ci = ar->i_ci; |
| 242 | func = ci->func; | ||
| 241 | lua_assert(ttisfunction(ci->func)); | 243 | lua_assert(ttisfunction(ci->func)); |
| 242 | f = clvalue(ci->func); | ||
| 243 | } | 244 | } |
| 244 | status = auxgetinfo(L, what, ar, f, ci); | 245 | cl = ttisclosure(func) ? clvalue(func) : NULL; |
| 246 | status = auxgetinfo(L, what, ar, cl, ci); | ||
| 245 | if (strchr(what, 'f')) { | 247 | if (strchr(what, 'f')) { |
| 246 | setclvalue(L, L->top, f); | 248 | setobjs2s(L, L->top, func); |
| 247 | incr_top(L); | 249 | incr_top(L); |
| 248 | } | 250 | } |
| 249 | if (strchr(what, 'L')) | 251 | if (strchr(what, 'L')) |
| 250 | collectvalidlines(L, f); | 252 | collectvalidlines(L, cl); |
| 251 | lua_unlock(L); | 253 | lua_unlock(L); |
| 252 | return status; | 254 | return status; |
| 253 | } | 255 | } |
| @@ -439,7 +441,7 @@ static const char *getupvalname (CallInfo *ci, const TValue *o, | |||
| 439 | void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { | 441 | void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { |
| 440 | CallInfo *ci = L->ci; | 442 | CallInfo *ci = L->ci; |
| 441 | const char *name = NULL; | 443 | const char *name = NULL; |
| 442 | const char *t = typename(ttype(o)); | 444 | const char *t = objtypename(o); |
| 443 | const char *kind = NULL; | 445 | const char *kind = NULL; |
| 444 | if (isLua(ci)) { | 446 | if (isLua(ci)) { |
| 445 | kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ | 447 | kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ |
| @@ -470,8 +472,8 @@ void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { | |||
| 470 | 472 | ||
| 471 | 473 | ||
| 472 | int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { | 474 | int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { |
| 473 | const char *t1 = typename(ttype(p1)); | 475 | const char *t1 = objtypename(p1); |
| 474 | const char *t2 = typename(ttype(p2)); | 476 | const char *t2 = objtypename(p2); |
| 475 | if (t1 == t2) | 477 | if (t1 == t2) |
| 476 | luaG_runerror(L, "attempt to compare two %s values", t1); | 478 | luaG_runerror(L, "attempt to compare two %s values", t1); |
| 477 | else | 479 | else |
