From 5bcfe0c700c1001b7e94e76214be12249bc051c7 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 6 Jan 2010 12:42:35 -0200 Subject: [PATCH] new debug info 'isvararg' and 'nparams' --- ldblib.c | 19 +++++++++++++------ ldebug.c | 10 +++++++++- lua.h | 4 +++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/ldblib.c b/ldblib.c index ce14d7dc..be132a3f 100644 --- a/ldblib.c +++ b/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.117 2009/11/24 12:05:44 roberto Exp roberto $ +** $Id: ldblib.c,v 1.118 2009/11/25 15:27:51 roberto Exp roberto $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ @@ -73,6 +73,12 @@ static void settabsi (lua_State *L, const char *i, int v) { } +static void settabsb (lua_State *L, const char *i, int v) { + lua_pushboolean(L, v); + lua_setfield(L, -2, i); +} + + static lua_State *getthread (lua_State *L, int *arg) { if (lua_isthread(L, 1)) { *arg = 1; @@ -127,16 +133,17 @@ static int db_getinfo (lua_State *L) { } if (strchr(options, 'l')) settabsi(L, "currentline", ar.currentline); - if (strchr(options, 'u')) + if (strchr(options, 'u')) { settabsi(L, "nups", ar.nups); + settabsi(L, "nparams", ar.nparams); + settabsb(L, "isvararg", ar.isvararg); + } if (strchr(options, 'n')) { settabss(L, "name", ar.name); settabss(L, "namewhat", ar.namewhat); } - if (strchr(options, 't')) { - lua_pushboolean(L, ar.istailcall); - lua_setfield(L, -2, "istailcall"); - } + if (strchr(options, 't')) + settabsb(L, "istailcall", ar.istailcall); if (strchr(options, 'L')) treatstackoption(L, L1, "activelines"); if (strchr(options, 'f')) diff --git a/ldebug.c b/ldebug.c index 76afe3c3..9b1a303c 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 2.59 2009/11/26 15:34:15 roberto Exp roberto $ +** $Id: ldebug.c,v 2.60 2009/12/01 16:31:04 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -192,6 +192,14 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, } case 'u': { ar->nups = f->c.nupvalues; + if (f->c.isC) { + ar->isvararg = 1; + ar->nparams = 0; + } + else { + ar->isvararg = f->l.p->is_vararg; + ar->nparams = f->l.p->numparams; + } break; } case 't': { diff --git a/lua.h b/lua.h index fd13b510..0704ea71 100644 --- a/lua.h +++ b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.257 2009/12/22 16:47:00 roberto Exp roberto $ +** $Id: lua.h,v 1.258 2010/01/05 18:33:26 roberto Exp roberto $ ** Lua - A Scripting Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -407,6 +407,8 @@ struct lua_Debug { int linedefined; /* (S) */ int lastlinedefined; /* (S) */ unsigned char nups; /* (u) number of upvalues */ + unsigned char nparams;/* (u) number of parameters */ + char isvararg; /* (u) */ char istailcall; /* (t) */ char short_src[LUA_IDSIZE]; /* (S) */ /* private part */