aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c43
1 files changed, 9 insertions, 34 deletions
diff --git a/ldebug.c b/ldebug.c
index a28b8ff9..722508f7 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.6 2000/01/25 13:57:18 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.7 2000/01/28 16:53:00 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*/
@@ -85,21 +85,6 @@ int lua_getstack (lua_State *L, int level, lua_Dbgactreg *ar) {
85} 85}
86 86
87 87
88static const char *luaG_getname (lua_State *L, const char **name, StkId top) {
89 StkId f = aux_stackedfunction(L, 0, top);
90 if (f == NULL || !hasdebuginfo(L, f) || ttype(f+2) == LUA_T_NIL)
91 return ""; /* no name available */
92 else {
93 int i = (f+2)->value.i;
94 if (ttype(f) == LUA_T_LCLMARK)
95 f = protovalue(f);
96 LUA_ASSERT(L, ttype(f) == LUA_T_LMARK, "must be a Lua function");
97 *name = tfvalue(f)->kstr[i]->str;
98 return luaO_typename(f+2);
99 }
100}
101
102
103static int lua_nups (StkId f) { 88static int lua_nups (StkId f) {
104 switch (ttype(f)) { 89 switch (ttype(f)) {
105 case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: 90 case LUA_T_LCLOSURE: case LUA_T_CCLOSURE:
@@ -131,10 +116,10 @@ int lua_getlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
131 if (!fp) return 0; /* `f' is not a Lua function? */ 116 if (!fp) return 0; /* `f' is not a Lua function? */
132 v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); 117 v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f));
133 if (!v->name) return 0; 118 if (!v->name) return 0;
134 /* if `name', there must be a LUA_T_LINE and a NAME */ 119 /* if `name', there must be a LUA_T_LINE */
135 /* therefore, f+3 points to function base */ 120 /* therefore, f+2 points to function base */
136 LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); 121 LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, "");
137 v->value = luaA_putluaObject(L, (f+3)+(v->index-1)); 122 v->value = luaA_putluaObject(L, (f+2)+(v->index-1));
138 return 1; 123 return 1;
139} 124}
140 125
@@ -146,7 +131,7 @@ int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
146 v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); 131 v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f));
147 if (!v->name) return 0; 132 if (!v->name) return 0;
148 LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); 133 LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, "");
149 *((f+3)+(v->index-1)) = *v->value; 134 *((f+2)+(v->index-1)) = *v->value;
150 return 1; 135 return 1;
151} 136}
152 137
@@ -181,8 +166,6 @@ static int checkfunc (lua_State *L, TObject *o) {
181 166
182static void lua_getobjname (lua_State *L, StkId f, lua_Dbgactreg *ar) { 167static void lua_getobjname (lua_State *L, StkId f, lua_Dbgactreg *ar) {
183 GlobalVar *g; 168 GlobalVar *g;
184 ar->namewhat = luaG_getname(L, &ar->name, f); /* caller debug information */
185 if (*ar->namewhat) return;
186 /* try to find a name for given function */ 169 /* try to find a name for given function */
187 setnormalized(L->top, f); /* to be used by `checkfunc' */ 170 setnormalized(L->top, f); /* to be used by `checkfunc' */
188 for (g=L->rootglobal; g; g=g->next) { 171 for (g=L->rootglobal; g; g=g->next) {
@@ -229,24 +212,16 @@ int lua_getinfo (lua_State *L, const char *what, lua_Dbgactreg *ar) {
229 212
230 213
231 214
232static void call_index_error (lua_State *L, TObject *o, const char *tp, 215static void call_index_error (lua_State *L, TObject *o, const char *v) {
233 const char *v) { 216 luaL_verror(L, "attempt to %.10s a %.10s value", v, lua_type(L, o));
234 const char *name;
235 const char *kind = luaG_getname(L, &name, L->top);
236 if (*kind) { /* is there a name? */
237 luaL_verror(L, "%.10s `%.30s' is not a %.10s", kind, name, tp);
238 }
239 else {
240 luaL_verror(L, "attempt to %.10s a %.10s value", v, lua_type(L, o));
241 }
242} 217}
243 218
244 219
245void luaG_callerror (lua_State *L, TObject *func) { 220void luaG_callerror (lua_State *L, TObject *func) {
246 call_index_error(L, func, "function", "call"); 221 call_index_error(L, func, "call");
247} 222}
248 223
249 224
250void luaG_indexerror (lua_State *L, TObject *t) { 225void luaG_indexerror (lua_State *L, TObject *t) {
251 call_index_error(L, t, "table", "index"); 226 call_index_error(L, t, "index");
252} 227}