From d80659759bcbcabf8b964356e5c9c867cd55effd Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 17 Oct 1995 12:12:45 -0200 Subject: [PATCH] new module luadebug.h. --- iolib.c | 33 +++++++++++++++++++++++++++++++-- lua.h | 4 +++- makefile | 8 ++++---- opcode.c | 7 ++++--- 4 files changed, 42 insertions(+), 10 deletions(-) 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); } diff --git a/lua.h b/lua.h index 33620bde..80c50e4c 100644 --- a/lua.h +++ b/lua.h @@ -2,7 +2,7 @@ ** LUA - Linguagem para Usuarios de Aplicacao ** Grupo de Tecnologia em Computacao Grafica ** TeCGraf - PUC-Rio -** $Id: lua.h,v 3.16 1995/01/27 17:19:06 celes Exp roberto $ +** $Id: lua.h,v 3.17 1995/10/06 14:11:10 roberto Exp roberto $ */ @@ -24,6 +24,8 @@ typedef enum LUA_T_ARRAY = -4, LUA_T_FUNCTION = -5, LUA_T_CFUNCTION= -6, + LUA_T_MARK = -7, + LUA_T_CMARK = -8, LUA_T_USERDATA = 0 } lua_Type; diff --git a/makefile b/makefile index bda6afb1..6898891e 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -# $Id: makefile,v 1.13 1995/10/04 19:19:46 roberto Exp roberto $ +# $Id: makefile,v 1.13 1995/10/09 18:51:49 roberto Exp roberto $ #configuration @@ -61,7 +61,7 @@ clear : rcsclean rm -f *.o rm -f parser.c parser.h - co lua.h lualib.h + co lua.h lualib.h luadebug.h % : RCS/%,v co $@ @@ -72,14 +72,14 @@ func.o : func.c table.h tree.h types.h opcode.h lua.h func.h mem.h hash.o : hash.c mem.h opcode.h lua.h types.h tree.h func.h hash.h table.h inout.o : inout.c mem.h opcode.h lua.h types.h tree.h func.h hash.h inout.h \ table.h -iolib.o : iolib.c lua.h lualib.h +iolib.o : iolib.c lua.h lualib.h luadebug.h lex.o : lex.c mem.h tree.h types.h table.h opcode.h lua.h func.h inout.h parser.h \ ugly.h lua.o : lua.c lua.h lualib.h mathlib.o : mathlib.c lualib.h lua.h mem.o : mem.c mem.h lua.h opcode.o : opcode.c mem.h opcode.h lua.h types.h tree.h func.h hash.h inout.h \ - table.h fallback.h + table.h fallback.h luadebug.h parser.o : parser.c mem.h opcode.h lua.h types.h tree.h func.h hash.h inout.h \ table.h strlib.o : strlib.c lua.h lualib.h diff --git a/opcode.c b/opcode.c index 5b5d7601..fce78f72 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.43 1995/10/13 15:16:25 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.44 1995/10/17 11:58:41 roberto Exp roberto $"; #include #include @@ -11,6 +11,7 @@ char *rcs_opcode="$Id: opcode.c,v 3.43 1995/10/13 15:16:25 roberto Exp roberto $ #include #include +#include "luadebug.h" #include "mem.h" #include "opcode.h" #include "hash.h" @@ -353,7 +354,7 @@ void lua_error (char *s) } -lua_Object luaD_stackedfunction (int level) +lua_Object lua_stackedfunction (int level) { Object *p = top; while (--p >= stack) @@ -364,7 +365,7 @@ lua_Object luaD_stackedfunction (int level) } -void luaD_funcInfo (lua_Object func, char **filename, char **funcname, +void lua_funcinfo (lua_Object func, char **filename, char **funcname, char **objname, int *linedefined) { return luaI_funcInfo(Address(func), filename, funcname, objname, linedefined);