From d80659759bcbcabf8b964356e5c9c867cd55effd Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 17 Oct 1995 12:12:45 -0200 Subject: new module luadebug.h. --- iolib.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'iolib.c') diff --git a/iolib.c b/iolib.c index 618afb4d..31eba5c5 100644 --- a/iolib.c +++ b/iolib.c @@ -3,7 +3,7 @@ ** Input/output library to LUA */ -char *rcs_iolib="$Id: iolib.c,v 1.22 1995/10/04 13:53:10 roberto Exp roberto $"; +char *rcs_iolib="$Id: iolib.c,v 1.23 1995/10/11 20:50:56 roberto Exp roberto $"; #include #include @@ -14,6 +14,7 @@ char *rcs_iolib="$Id: iolib.c,v 1.22 1995/10/04 13:53:10 roberto Exp roberto $"; #include #include "lua.h" +#include "luadebug.h" #include "lualib.h" static FILE *in=stdin, *out=stdout; @@ -580,7 +581,7 @@ static void io_exit (void) { lua_Object o = lua_getparam(1); if (lua_isstring(o)) - printf("%s\n", lua_getstring(o)); + fprintf(stderr, "%s\n", lua_getstring(o)); exit(1); } @@ -600,6 +601,33 @@ static void io_debug (void) } } + +static void print_message (void) +{ + lua_Object o = lua_getparam(1); + char *s = lua_isstring(o) ? lua_getstring(o) : "(no messsage)"; + int level = 0; + lua_Object func; + fprintf(stderr, "lua: %s\n", s); + fprintf(stderr, "Active Stack:\n"); + while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) + { + char *filename; char *funcname; + char *objname; int linedefined; + lua_funcinfo(func, &filename, &funcname, &objname, &linedefined); + if (objname == NULL) + if (funcname) + fprintf(stderr, "\t%s\n", funcname); + else + { + fprintf(stderr, "\tmain of %s\n", filename); + } + else + fprintf(stderr, "\t%s:%s\n", objname, funcname); +/* fprintf(stderr, "\t(in file: %s)\n", filename); */ + } +} + /* ** Open io library */ @@ -619,4 +647,5 @@ void iolib_open (void) lua_register ("beep", io_beep); lua_register ("exit", io_exit); lua_register ("debug", io_debug); + lua_setfallback("error", print_message); } -- cgit v1.2.3-55-g6feb