diff options
Diffstat (limited to '')
| -rw-r--r-- | iolib.c | 33 |
1 files changed, 31 insertions, 2 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Input/output library to LUA | 3 | ** Input/output library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_iolib="$Id: iolib.c,v 1.22 1995/10/04 13:53:10 roberto Exp roberto $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.23 1995/10/11 20:50:56 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <ctype.h> | 9 | #include <ctype.h> |
| @@ -14,6 +14,7 @@ char *rcs_iolib="$Id: iolib.c,v 1.22 1995/10/04 13:53:10 roberto Exp roberto $"; | |||
| 14 | #include <stdlib.h> | 14 | #include <stdlib.h> |
| 15 | 15 | ||
| 16 | #include "lua.h" | 16 | #include "lua.h" |
| 17 | #include "luadebug.h" | ||
| 17 | #include "lualib.h" | 18 | #include "lualib.h" |
| 18 | 19 | ||
| 19 | static FILE *in=stdin, *out=stdout; | 20 | static FILE *in=stdin, *out=stdout; |
| @@ -580,7 +581,7 @@ static void io_exit (void) | |||
| 580 | { | 581 | { |
| 581 | lua_Object o = lua_getparam(1); | 582 | lua_Object o = lua_getparam(1); |
| 582 | if (lua_isstring(o)) | 583 | if (lua_isstring(o)) |
| 583 | printf("%s\n", lua_getstring(o)); | 584 | fprintf(stderr, "%s\n", lua_getstring(o)); |
| 584 | exit(1); | 585 | exit(1); |
| 585 | } | 586 | } |
| 586 | 587 | ||
| @@ -600,6 +601,33 @@ static void io_debug (void) | |||
| 600 | } | 601 | } |
| 601 | } | 602 | } |
| 602 | 603 | ||
| 604 | |||
| 605 | static void print_message (void) | ||
| 606 | { | ||
| 607 | lua_Object o = lua_getparam(1); | ||
| 608 | char *s = lua_isstring(o) ? lua_getstring(o) : "(no messsage)"; | ||
| 609 | int level = 0; | ||
| 610 | lua_Object func; | ||
| 611 | fprintf(stderr, "lua: %s\n", s); | ||
| 612 | fprintf(stderr, "Active Stack:\n"); | ||
| 613 | while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) | ||
| 614 | { | ||
| 615 | char *filename; char *funcname; | ||
| 616 | char *objname; int linedefined; | ||
| 617 | lua_funcinfo(func, &filename, &funcname, &objname, &linedefined); | ||
| 618 | if (objname == NULL) | ||
| 619 | if (funcname) | ||
| 620 | fprintf(stderr, "\t%s\n", funcname); | ||
| 621 | else | ||
| 622 | { | ||
| 623 | fprintf(stderr, "\tmain of %s\n", filename); | ||
| 624 | } | ||
| 625 | else | ||
| 626 | fprintf(stderr, "\t%s:%s\n", objname, funcname); | ||
| 627 | /* fprintf(stderr, "\t(in file: %s)\n", filename); */ | ||
| 628 | } | ||
| 629 | } | ||
| 630 | |||
| 603 | /* | 631 | /* |
| 604 | ** Open io library | 632 | ** Open io library |
| 605 | */ | 633 | */ |
| @@ -619,4 +647,5 @@ void iolib_open (void) | |||
| 619 | lua_register ("beep", io_beep); | 647 | lua_register ("beep", io_beep); |
| 620 | lua_register ("exit", io_exit); | 648 | lua_register ("exit", io_exit); |
| 621 | lua_register ("debug", io_debug); | 649 | lua_register ("debug", io_debug); |
| 650 | lua_setfallback("error", print_message); | ||
| 622 | } | 651 | } |
