From cc117253c83ec32d226a8f2226d5ca144804f873 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 21 Aug 1998 14:43:44 -0300 Subject: new implementation for error handling: on error, function _ERRORMESSAGE is called, which in turn calls _ALERT to write a message to stderr. --- lbuiltin.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lbuiltin.c') diff --git a/lbuiltin.c b/lbuiltin.c index 43023e8e..58c9509c 100644 --- a/lbuiltin.c +++ b/lbuiltin.c @@ -1,5 +1,5 @@ /* -** $Id: lbuiltin.c,v 1.32 1998/06/29 18:24:06 roberto Exp roberto $ +** $Id: lbuiltin.c,v 1.33 1998/07/12 16:16:43 roberto Exp roberto $ ** Built-in functions ** See Copyright Notice in lua.h */ @@ -192,6 +192,19 @@ static void luaI_print (void) { } +static void luaB_message (void) { + fputs(luaL_check_string(1), stderr); +} + + +static void error_message (void) { + char buff[200]; + sprintf(buff, "lua error: %.180s\n", luaL_check_string(1)); + lua_pushstring(buff); + lua_call("_ALERT"); +} + + static void luaI_type (void) { lua_Object o = luaL_nonnullarg(1); @@ -568,6 +581,7 @@ static struct luaL_reg int_funcs[] = { {"copytagmethods", copytagmethods}, {"dostring", internaldostring}, {"error", luaI_error}, + {"_ERRORMESSAGE", error_message}, {"foreach", foreach}, {"foreachvar", foreachvar}, {"getglobal", getglobal}, @@ -588,7 +602,8 @@ static struct luaL_reg int_funcs[] = { {"tonumber", luaB_tonumber}, {"tostring", to_string}, {"tag", luatag}, - {"type", luaI_type} + {"type", luaI_type}, + {"_ALERT", luaB_message} }; -- cgit v1.2.3-55-g6feb