diff options
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 33 |
1 files changed, 15 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.78 2000/09/11 17:38:42 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.79 2000/09/11 20:29:27 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 | */ |
@@ -590,30 +590,27 @@ static int errorfb (lua_State *L) { | |||
590 | int level = 1; /* skip level 0 (it's this function) */ | 590 | int level = 1; /* skip level 0 (it's this function) */ |
591 | int firstpart = 1; /* still before eventual `...' */ | 591 | int firstpart = 1; /* still before eventual `...' */ |
592 | lua_Debug ar; | 592 | lua_Debug ar; |
593 | lua_settop(L, 1); | 593 | luaL_Buffer b; |
594 | luaL_checktype(L, 1, "string"); | 594 | luaL_buffinit(L, &b); |
595 | lua_pushstring(L, "error: "); | 595 | luaL_addstring(&b, "error: "); |
596 | lua_insert(L, 1); | 596 | luaL_addstring(&b, luaL_check_string(L, 1)); |
597 | lua_pushstring(L, "\nstack traceback:\n"); | 597 | luaL_addstring(&b, "\nstack traceback:\n"); |
598 | lua_concat(L, 3); | ||
599 | while (lua_getstack(L, level++, &ar)) { | 598 | while (lua_getstack(L, level++, &ar)) { |
600 | char buff[120]; /* enough to fit following `sprintf's */ | 599 | char buff[120]; /* enough to fit following `sprintf's */ |
601 | int toconcat = 1; /* number of strings in the stack to concat */ | ||
602 | if (level > LEVELS1 && firstpart) { | 600 | if (level > LEVELS1 && firstpart) { |
603 | /* no more than `LEVELS2' more levels? */ | 601 | /* no more than `LEVELS2' more levels? */ |
604 | if (!lua_getstack(L, level+LEVELS2, &ar)) | 602 | if (!lua_getstack(L, level+LEVELS2, &ar)) |
605 | level--; /* keep going */ | 603 | level--; /* keep going */ |
606 | else { | 604 | else { |
607 | lua_pushstring(L, " ...\n"); /* too many levels */ | 605 | luaL_addstring(&b, " ...\n"); /* too many levels */ |
608 | lua_concat(L, 2); | ||
609 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ | 606 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ |
610 | level++; | 607 | level++; |
611 | } | 608 | } |
612 | firstpart = 0; | 609 | firstpart = 0; |
613 | continue; | 610 | continue; |
614 | } | 611 | } |
615 | sprintf(buff, "%4d: ", level-1); | 612 | sprintf(buff, "%4d: ", level-1); |
616 | lua_pushstring(L, buff); toconcat++; | 613 | luaL_addstring(&b, buff); |
617 | lua_getinfo(L, "Snl", &ar); | 614 | lua_getinfo(L, "Snl", &ar); |
618 | switch (*ar.namewhat) { | 615 | switch (*ar.namewhat) { |
619 | case 'g': case 'l': /* global, local */ | 616 | case 'g': case 'l': /* global, local */ |
@@ -632,21 +629,21 @@ static int errorfb (lua_State *L) { | |||
632 | sprintf(buff, "%.70s", ar.source_id); | 629 | sprintf(buff, "%.70s", ar.source_id); |
633 | else | 630 | else |
634 | sprintf(buff, "function <%d:%.70s>", ar.linedefined, ar.source_id); | 631 | sprintf(buff, "function <%d:%.70s>", ar.linedefined, ar.source_id); |
635 | ar.source = NULL; | 632 | ar.source = NULL; /* do not print source again */ |
636 | } | 633 | } |
637 | } | 634 | } |
638 | lua_pushstring(L, buff); toconcat++; | 635 | luaL_addstring(&b, buff); |
639 | if (ar.currentline > 0) { | 636 | if (ar.currentline > 0) { |
640 | sprintf(buff, " at line %d", ar.currentline); | 637 | sprintf(buff, " at line %d", ar.currentline); |
641 | lua_pushstring(L, buff); toconcat++; | 638 | luaL_addstring(&b, buff); |
642 | } | 639 | } |
643 | if (ar.source) { | 640 | if (ar.source) { |
644 | sprintf(buff, " [%.70s]", ar.source_id); | 641 | sprintf(buff, " [%.70s]", ar.source_id); |
645 | lua_pushstring(L, buff); toconcat++; | 642 | luaL_addstring(&b, buff); |
646 | } | 643 | } |
647 | lua_pushstring(L, "\n"); toconcat++; | 644 | luaL_addstring(&b, "\n"); |
648 | lua_concat(L, toconcat); | ||
649 | } | 645 | } |
646 | luaL_pushresult(&b); | ||
650 | lua_getglobals(L); | 647 | lua_getglobals(L); |
651 | lua_pushstring(L, LUA_ALERT); | 648 | lua_pushstring(L, LUA_ALERT); |
652 | lua_rawget(L, -2); | 649 | lua_rawget(L, -2); |