From ec79f25286a4ac843280ae7377ec1e5b39a70cea Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 16 May 1995 14:23:58 -0300 Subject: new lua function "getstack"; new interface to function luaI_reportbug. --- inout.c | 26 ++++++++++++++++++++++---- inout.h | 8 +++----- opcode.c | 8 ++------ table.c | 4 +++- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/inout.c b/inout.c index 9ea0fd82..afb0ee52 100644 --- a/inout.c +++ b/inout.c @@ -5,7 +5,7 @@ ** Also provides some predefined lua functions. */ -char *rcs_inout="$Id: inout.c,v 2.18 1995/03/17 20:42:20 roberto Exp roberto $"; +char *rcs_inout="$Id: inout.c,v 2.19 1995/05/02 18:43:03 roberto Exp roberto $"; #include #include @@ -19,6 +19,14 @@ char *rcs_inout="$Id: inout.c,v 2.18 1995/03/17 20:42:20 roberto Exp roberto $"; #include "tree.h" #include "lua.h" + +#ifndef MAXFUNCSTACK +#define MAXFUNCSTACK 100 +#endif + +#define MAXMESSAGE MAXFUNCSTACK*80 + + /* Exported variables */ Word lua_linenumber; Bool lua_debug; @@ -145,10 +153,12 @@ void lua_popfunction (void) } /* -** Report bug building a message. +** Report bug building a message and pushing it on the stack. */ -void luaI_reportbug (char *msg, int size) +void luaI_reportbug (char *s, int err) { + char msg[MAXMESSAGE]; + strcpy (msg, s); if (lua_debugline != 0) { if (funcStack) @@ -163,7 +173,7 @@ void luaI_reportbug (char *msg, int size) lua_constant[func->function]->str, func->file, line); line = func->line; func = func->next; - lua_popfunction(); + if (err) lua_popfunction(); } while (func); } else @@ -173,6 +183,7 @@ void luaI_reportbug (char *msg, int size) lua_debugline, lua_filename()); } } + lua_pushstring(msg); } @@ -288,3 +299,10 @@ void luaI_error (void) lua_error(s); } +void luaI_getstack (void) +{ + char *s = lua_getstring(lua_getparam(1)); + if (s == NULL) s = ""; + luaI_reportbug(s, 0); +} + diff --git a/inout.h b/inout.h index ae84f133..fee22d15 100644 --- a/inout.h +++ b/inout.h @@ -1,5 +1,5 @@ /* -** $Id: inout.h,v 1.7 1994/12/20 21:20:36 roberto Exp roberto $ +** $Id: inout.h,v 1.8 1995/05/02 18:43:03 roberto Exp roberto $ */ @@ -8,9 +8,6 @@ #include "types.h" -#ifndef MAXFUNCSTACK -#define MAXFUNCSTACK 100 -#endif extern Word lua_linenumber; extern Bool lua_debug; @@ -22,13 +19,14 @@ char *lua_openstring (char *s); void lua_closestring (void); void lua_pushfunction (char *file, Word function); void lua_popfunction (void); -void luaI_reportbug (char *s, int size); +void luaI_reportbug (char *s, int err); void lua_internaldofile (void); void lua_internaldostring (void); void lua_print (void); void luaI_type (void); void lua_obj2number (void); +void luaI_getstack (void); void luaI_error (void); #endif diff --git a/opcode.c b/opcode.c index 152970aa..fe5c6dfc 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.36 1995/04/11 17:56:30 celes Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.37 1995/05/02 18:43:03 roberto Exp roberto $"; #include #include @@ -68,14 +68,10 @@ Object *luaI_Address (lua_Object o) ** Error messages */ -#define MAXMESSAGE MAXFUNCSTACK*80 static void lua_message (char *s) { - char msg[MAXMESSAGE]; - strcpy (msg, s); - luaI_reportbug(msg, MAXMESSAGE-strlen(s)); - lua_pushstring(msg); + luaI_reportbug(s, 1); do_call(&luaI_fallBacks[FB_ERROR].function, (top-stack)-1, 0, (top-stack)-1); } diff --git a/table.c b/table.c index 75fa21f2..d3fb89c3 100644 --- a/table.c +++ b/table.c @@ -3,7 +3,7 @@ ** Module to control static tables */ -char *rcs_table="$Id: table.c,v 2.28 1995/01/18 20:15:54 celes Exp roberto $"; +char *rcs_table="$Id: table.c,v 2.29 1995/05/02 18:43:03 roberto Exp roberto $"; #include @@ -68,6 +68,8 @@ static void lua_initsymbol (void) s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; n = luaI_findsymbolbyname("setfallback"); s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback; + n = luaI_findsymbolbyname("getstack"); + s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_getstack; n = luaI_findsymbolbyname("error"); s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error; } -- cgit v1.2.3-55-g6feb