Bläddra i källkod

print error on stderr when _ALERT is not defined

Roberto Ierusalimschy 23 år sedan
förälder
incheckning
11886dc7b0
1 ändrade filer med 9 tillägg och 4 borttagningar
  1. 9 4
      lauxlib.c

+ 9 - 4
lauxlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.c,v 1.87 2002/10/04 14:31:40 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.88 2002/10/16 20:41:35 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -422,9 +422,14 @@ LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size,
 static void callalert (lua_State *L, int status) {
   if (status != 0) {
     lua_getglobal(L, "_ALERT");
-    lua_insert(L, -2);
-    lua_call(L, 1, 0);
-    lua_pop(L, 1);
+    if (lua_isfunction(L, -1)) {
+      lua_insert(L, -2);
+      lua_call(L, 1, 0);
+    }
+    else {  /* no _ALERT function; print it on stderr */
+      fprintf(stderr, "%s\n", lua_tostring(L, -2));
+      lua_pop(L, 2);  /* remove error message and _ALERT */
+    }
   }
 }