better control over calls to _ALERT and _ERRORMESSAGE (to avoid error
loops)
This commit is contained in:
20
lbuiltin.c
20
lbuiltin.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lbuiltin.c,v 1.50 1999/02/08 16:29:35 roberto Exp roberto $
|
** $Id: lbuiltin.c,v 1.51 1999/02/12 19:23:02 roberto Exp roberto $
|
||||||
** Built-in functions
|
** Built-in functions
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -82,9 +82,8 @@ static Hash *gethash (int arg) {
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** If your system does not support "stderr", remove this function and
|
** If your system does not support "stderr", redefine this function, or
|
||||||
** define your own "_ALERT" function. You *must* have an _ALERT function
|
** redefine _ERRORMESSAGE so that it won't need _ALERT.
|
||||||
** defined for Lua to work properly.
|
|
||||||
*/
|
*/
|
||||||
static void luaB_alert (void) {
|
static void luaB_alert (void) {
|
||||||
fputs(luaL_check_string(1), stderr);
|
fputs(luaL_check_string(1), stderr);
|
||||||
@@ -96,10 +95,13 @@ static void luaB_alert (void) {
|
|||||||
** The library "iolib" redefines _ERRORMESSAGE for better error information.
|
** The library "iolib" redefines _ERRORMESSAGE for better error information.
|
||||||
*/
|
*/
|
||||||
static void error_message (void) {
|
static void error_message (void) {
|
||||||
|
lua_Object al = lua_rawgetglobal("_ALERT");
|
||||||
|
if (lua_isfunction(al)) { /* avoid error loop if _ALERT is not defined */
|
||||||
char buff[600];
|
char buff[600];
|
||||||
sprintf(buff, "lua error: %.500s\n", luaL_check_string(1));
|
sprintf(buff, "lua error: %.500s\n", luaL_check_string(1));
|
||||||
lua_pushstring(buff);
|
lua_pushstring(buff);
|
||||||
lua_call("_ALERT");
|
lua_callfunction(al);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -301,7 +303,6 @@ static void luaB_call (void) {
|
|||||||
/* }====================================================== */
|
/* }====================================================== */
|
||||||
|
|
||||||
|
|
||||||
#ifdef EXTRALIB
|
|
||||||
/*
|
/*
|
||||||
** {======================================================
|
** {======================================================
|
||||||
** "Extra" functions
|
** "Extra" functions
|
||||||
@@ -501,7 +502,6 @@ static void luaB_sort (void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* }}===================================================== */
|
/* }}===================================================== */
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -709,10 +709,9 @@ static struct luaL_reg builtin_funcs[] = {
|
|||||||
{"tag", luaB_luatag},
|
{"tag", luaB_luatag},
|
||||||
{"tonumber", luaB_tonumber},
|
{"tonumber", luaB_tonumber},
|
||||||
{"tostring", luaB_tostring},
|
{"tostring", luaB_tostring},
|
||||||
{"type", luaB_type}
|
{"type", luaB_type},
|
||||||
#ifdef EXTRALIB
|
|
||||||
/* "Extra" functions */
|
/* "Extra" functions */
|
||||||
,{"assert", luaB_assert},
|
{"assert", luaB_assert},
|
||||||
{"foreach", luaB_foreach},
|
{"foreach", luaB_foreach},
|
||||||
{"foreachi", luaB_foreachi},
|
{"foreachi", luaB_foreachi},
|
||||||
{"foreachvar", luaB_foreachvar},
|
{"foreachvar", luaB_foreachvar},
|
||||||
@@ -720,7 +719,6 @@ static struct luaL_reg builtin_funcs[] = {
|
|||||||
{"sort", luaB_sort},
|
{"sort", luaB_sort},
|
||||||
{"tinsert", luaB_tinsert},
|
{"tinsert", luaB_tinsert},
|
||||||
{"tremove", luaB_tremove}
|
{"tremove", luaB_tremove}
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
ldo.c
11
ldo.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ldo.c,v 1.32 1999/02/12 19:23:02 roberto Exp roberto $
|
** $Id: ldo.c,v 1.33 1999/02/22 13:51:44 roberto Exp roberto $
|
||||||
** Stack and Call structure of Lua
|
** Stack and Call structure of Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -235,7 +235,8 @@ void luaD_travstack (int (*fn)(TObject *))
|
|||||||
|
|
||||||
static void message (char *s) {
|
static void message (char *s) {
|
||||||
TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval);
|
TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval);
|
||||||
if (ttype(em) != LUA_T_NIL) {
|
if (ttype(em) == LUA_T_PROTO || ttype(em) == LUA_T_CPROTO ||
|
||||||
|
ttype(em) == LUA_T_CLOSURE) {
|
||||||
*L->stack.top = *em;
|
*L->stack.top = *em;
|
||||||
incr_top;
|
incr_top;
|
||||||
lua_pushstring(s);
|
lua_pushstring(s);
|
||||||
@@ -246,14 +247,12 @@ static void message (char *s) {
|
|||||||
/*
|
/*
|
||||||
** Reports an error, and jumps up to the available recover label
|
** Reports an error, and jumps up to the available recover label
|
||||||
*/
|
*/
|
||||||
void lua_error (char *s)
|
void lua_error (char *s) {
|
||||||
{
|
|
||||||
if (s) message(s);
|
if (s) message(s);
|
||||||
if (L->errorJmp)
|
if (L->errorJmp)
|
||||||
longjmp(*((jmp_buf *)L->errorJmp), 1);
|
longjmp(*((jmp_buf *)L->errorJmp), 1);
|
||||||
else {
|
else {
|
||||||
lua_pushstring("lua: exit(1). Unable to recover.\n");
|
message("exit(1). Unable to recover.\n");
|
||||||
lua_call("_ALERT");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
liolib.c
9
liolib.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: liolib.c,v 1.29 1999/01/04 12:41:12 roberto Exp roberto $
|
** $Id: liolib.c,v 1.30 1999/02/05 15:22:43 roberto Exp roberto $
|
||||||
** Standard I/O (and system) library
|
** Standard I/O (and system) library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -459,7 +459,7 @@ static void errorfb (void) {
|
|||||||
char buff[MAXMESSAGE];
|
char buff[MAXMESSAGE];
|
||||||
int level = 1; /* skip level 0 (it's this function) */
|
int level = 1; /* skip level 0 (it's this function) */
|
||||||
lua_Object func;
|
lua_Object func;
|
||||||
sprintf(buff, "lua: %.200s\n", lua_getstring(lua_getparam(1)));
|
sprintf(buff, "lua error: %.200s\n", lua_getstring(lua_getparam(1)));
|
||||||
while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) {
|
while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) {
|
||||||
char *name;
|
char *name;
|
||||||
int currentline;
|
int currentline;
|
||||||
@@ -496,8 +496,11 @@ static void errorfb (void) {
|
|||||||
sprintf(buff+strlen(buff), " [in chunk %.50s]", chunkname);
|
sprintf(buff+strlen(buff), " [in chunk %.50s]", chunkname);
|
||||||
strcat(buff, "\n");
|
strcat(buff, "\n");
|
||||||
}
|
}
|
||||||
|
func = lua_rawgetglobal("_ALERT");
|
||||||
|
if (lua_isfunction(func)) { /* avoid error loop if _ALERT is not defined */
|
||||||
lua_pushstring(buff);
|
lua_pushstring(buff);
|
||||||
lua_call("_ALERT");
|
lua_callfunction(func);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user