aboutsummaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-01-19 10:00:45 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-01-19 10:00:45 -0200
commit2877bad4c260d11c22c3b12e633d6b1ca3415789 (patch)
tree2109684c4521c34b584bfd24e0eae05688c7fc32 /liolib.c
parent27163f032eed6b851b98a0ab67b1387d701e61c0 (diff)
downloadlua-2877bad4c260d11c22c3b12e633d6b1ca3415789.tar.gz
lua-2877bad4c260d11c22c3b12e633d6b1ca3415789.tar.bz2
lua-2877bad4c260d11c22c3b12e633d6b1ca3415789.zip
new debug API (first version)
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/liolib.c b/liolib.c
index b58bcaff..e9f114fe 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.54 1999/12/28 11:52:49 roberto Exp roberto $ 2** $Id: liolib.c,v 1.55 1999/12/30 18:28:40 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -529,53 +529,49 @@ static void io_debug (lua_State *L) {
529static void errorfb (lua_State *L) { 529static void errorfb (lua_State *L) {
530 char buff[MAXMESSAGE]; 530 char buff[MAXMESSAGE];
531 int level = 1; /* skip level 0 (it's this function) */ 531 int level = 1; /* skip level 0 (it's this function) */
532 lua_Object func; 532 lua_Dbgactreg ar;
533 lua_Object alertfunc = lua_rawgetglobal(L, "_ALERT");
533 sprintf(buff, "error: %.200s\n", lua_getstring(L, lua_getparam(L, 1))); 534 sprintf(buff, "error: %.200s\n", lua_getstring(L, lua_getparam(L, 1)));
534 while ((func = lua_stackedfunction(L, level++)) != LUA_NOOBJECT) { 535 while (lua_getstack(L, level++, &ar)) {
535 const char *name;
536 int currentline;
537 const char *chunkname;
538 char buffchunk[MAXSRC]; 536 char buffchunk[MAXSRC];
539 int linedefined; 537 lua_getinfo(L, "Snl", &ar);
540 lua_funcinfo(L, func, &chunkname, &linedefined); 538 luaL_chunkid(buffchunk, ar.source, sizeof(buffchunk));
541 luaL_chunkid(buffchunk, chunkname, sizeof(buffchunk));
542 if (level == 2) strcat(buff, "Active Stack:\n"); 539 if (level == 2) strcat(buff, "Active Stack:\n");
543 strcat(buff, " "); 540 strcat(buff, " ");
544 if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) { 541 if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) {
545 strcat(buff, "...\n"); 542 strcat(buff, "...\n");
546 break; /* buffer is full */ 543 break; /* buffer is full */
547 } 544 }
548 switch (*lua_getobjname(L, func, &name)) { 545 switch (*ar.namewhat) {
549 case 'g': case 'l': 546 case 'g': case 'l': /* global, local */
550 sprintf(buff+strlen(buff), "function `%.50s'", name); 547 sprintf(buff+strlen(buff), "function `%.50s'", ar.name);
551 break; 548 break;
552 case 'f': 549 case 'f': /* field */
553 sprintf(buff+strlen(buff), "method `%.50s'", name); 550 sprintf(buff+strlen(buff), "method `%.50s'", ar.name);
554 break; 551 break;
555 case 't': 552 case 't': /* tag method */
556 sprintf(buff+strlen(buff), "`%.50s' tag method", name); 553 sprintf(buff+strlen(buff), "`%.50s' tag method", ar.name);
557 break; 554 break;
558 default: { 555 default: {
559 if (linedefined == 0) 556 if (*ar.what == 'm') /* main? */
560 sprintf(buff+strlen(buff), "main of %.70s", buffchunk); 557 sprintf(buff+strlen(buff), "main of %.70s", buffchunk);
561 else if (linedefined < 0) 558 else if (*ar.what == 'C') /* C function? */
562 sprintf(buff+strlen(buff), "%.70s", buffchunk); 559 sprintf(buff+strlen(buff), "%.70s", buffchunk);
563 else 560 else
564 sprintf(buff+strlen(buff), "function <%d:%.70s>", 561 sprintf(buff+strlen(buff), "function <%d:%.70s>",
565 linedefined, buffchunk); 562 ar.linedefined, buffchunk);
566 chunkname = NULL; 563 ar.source = NULL;
567 } 564 }
568 } 565 }
569 if ((currentline = lua_currentline(L, func)) > 0) 566 if (ar.currentline > 0)
570 sprintf(buff+strlen(buff), " at line %d", currentline); 567 sprintf(buff+strlen(buff), " at line %d", ar.currentline);
571 if (chunkname) 568 if (ar.source)
572 sprintf(buff+strlen(buff), " [%.70s]", buffchunk); 569 sprintf(buff+strlen(buff), " [%.70s]", buffchunk);
573 strcat(buff, "\n"); 570 strcat(buff, "\n");
574 } 571 }
575 func = lua_rawgetglobal(L, "_ALERT"); 572 if (lua_isfunction(L, alertfunc)) { /* avoid loop if _ALERT is not defined */
576 if (lua_isfunction(L, func)) { /* avoid error loop if _ALERT is not defined */
577 lua_pushstring(L, buff); 573 lua_pushstring(L, buff);
578 lua_callfunction(L, func); 574 lua_callfunction(L, alertfunc);
579 } 575 }
580} 576}
581 577