Browse Source

_ALERT is a private afair of lua.c

Roberto Ierusalimschy 23 years ago
parent
commit
f53fd8d5f5
2 changed files with 15 additions and 19 deletions
  1. 1 13
      lbaselib.c
  2. 14 6
      lua.c

+ 1 - 13
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
 ** Basic library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -20,17 +20,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 your system does not support `stdout', you can just remove this function.
 ** If you need, you can define your own `print' function, following this
 ** If you need, you can define your own `print' function, following this
@@ -385,7 +374,6 @@ static int luaB_require (lua_State *L) {
 
 
 
 
 static const luaL_reg base_funcs[] = {
 static const luaL_reg base_funcs[] = {
-  {LUA_ALERT, luaB__ALERT},
   {"error", luaB_error},
   {"error", luaB_error},
   {"metatable", luaB_metatable},
   {"metatable", luaB_metatable},
   {"globals", luaB_globals},
   {"globals", luaB_globals},

+ 14 - 6
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
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -69,9 +69,9 @@ static void laction (int i) {
 static void report (int status) {
 static void report (int status) {
   if (status == 0) return;
   if (status == 0) return;
   else {
   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);
     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) {
 static int l_getargs (lua_State *l) {
   char **argv = (char **)lua_touserdata(l, lua_upvalueindex(1));
   char **argv = (char **)lua_touserdata(l, lua_upvalueindex(1));
   getargs(argv);
   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_pushudataval(L, argv);
   lua_pushcclosure(L, l_getargs, 1);
   lua_pushcclosure(L, l_getargs, 1);
   lua_setglobal(L, "getargs");
   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 */
   (void)argc;  /* to avoid warnings */
   L = lua_open();  /* create state */
   L = lua_open();  /* create state */
   LUA_USERINIT(L);  /* open libraries */
   LUA_USERINIT(L);  /* open libraries */
-  register_getargs(argv);  /* create `getargs' function */
+  register_own(argv);  /* create own function */
   status = handle_luainit();
   status = handle_luainit();
   if (status != 0) return status;
   if (status != 0) return status;
   status = handle_argv(argv+1, &toclose);
   status = handle_argv(argv+1, &toclose);