commit f53fd8d5f5f6c06afb191c5f579c75fcf607d52d
parent 955def034814e96f5f8e42def2e47ca6817ef103
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 16 May 2002 16:08:57 -0300
_ALERT is a private afair of lua.c
Diffstat:
2 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/lbaselib.c b/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.73 2002/05/13 13:10:58 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.74 2002/05/16 18:39:46 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -21,17 +21,6 @@
/*
-** If your system does not support `stderr', redefine this function, or
-** redefine _ERRORMESSAGE so that it won't need _ALERT.
-*/
-static int luaB__ALERT (lua_State *L) {
- fputs(luaL_check_string(L, 1), stderr);
- putc('\n', stderr);
- return 0;
-}
-
-
-/*
** If your system does not support `stdout', you can just remove this function.
** If you need, you can define your own `print' function, following this
** model but changing `fputs' to put the strings at a proper place
@@ -385,7 +374,6 @@ static int luaB_require (lua_State *L) {
static const luaL_reg base_funcs[] = {
- {LUA_ALERT, luaB__ALERT},
{"error", luaB_error},
{"metatable", luaB_metatable},
{"globals", luaB_globals},
diff --git a/lua.c b/lua.c
@@ -1,5 +1,5 @@
/*
-** $Id: lua.c,v 1.85 2002/05/01 20:40:42 roberto Exp roberto $
+** $Id: lua.c,v 1.86 2002/05/15 18:57:44 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@@ -69,9 +69,9 @@ static void laction (int i) {
static void report (int status) {
if (status == 0) return;
else {
- const char *msg = lua_tostring(L, -1);
- if (msg == NULL) msg = "(no message)";
- fprintf(stderr, "%s\n", msg);
+ lua_getglobal(L, "_ALERT");
+ lua_pushvalue(L, -2);
+ lua_pcall(L, 1, 0, 0);
lua_pop(L, 1);
}
}
@@ -137,6 +137,13 @@ static void getargs (char *argv[]) {
}
+static int l_alert (lua_State *l) {
+ fputs(luaL_check_string(l, 1), stderr);
+ putc('\n', stderr);
+ return 0;
+}
+
+
static int l_getargs (lua_State *l) {
char **argv = (char **)lua_touserdata(l, lua_upvalueindex(1));
getargs(argv);
@@ -323,10 +330,11 @@ static int handle_argv (char *argv[], int *toclose) {
}
-static void register_getargs (char *argv[]) {
+static void register_own (char *argv[]) {
lua_pushudataval(L, argv);
lua_pushcclosure(L, l_getargs, 1);
lua_setglobal(L, "getargs");
+ lua_register(L, "_ALERT", l_alert);
}
@@ -356,7 +364,7 @@ int main (int argc, char *argv[]) {
(void)argc; /* to avoid warnings */
L = lua_open(); /* create state */
LUA_USERINIT(L); /* open libraries */
- register_getargs(argv); /* create `getargs' function */
+ register_own(argv); /* create own function */
status = handle_luainit();
if (status != 0) return status;
status = handle_argv(argv+1, &toclose);