Przeglądaj źródła

`error()' (and `error(nil)') generates errors with no error messages

Roberto Ierusalimschy 22 lat temu
rodzic
commit
275c150b17
2 zmienionych plików z 7 dodań i 10 usunięć
  1. 3 5
      lbaselib.c
  2. 4 5
      lua.c

+ 3 - 5
lbaselib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lbaselib.c,v 1.134 2003/10/07 20:13:41 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.135 2003/10/10 12:57:55 roberto Exp roberto $
 ** Basic library
 ** See Copyright Notice in lua.h
 */
@@ -78,10 +78,8 @@ static int luaB_tonumber (lua_State *L) {
 
 static int luaB_error (lua_State *L) {
   int level = luaL_optint(L, 2, 1);
-  luaL_checkany(L, 1);
-  if (!lua_isstring(L, 1) || level == 0)
-    lua_pushvalue(L, 1);  /* propagate error message without changes */
-  else {  /* add extra information */
+  lua_settop(L, 1);
+  if (lua_isstring(L, 1) && level > 0) {  /* add extra information? */
     luaL_where(L, level);
     lua_pushvalue(L, 1);
     lua_concat(L, 2);

+ 4 - 5
lua.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.c,v 1.122 2003/04/03 13:34:42 roberto Exp roberto $
+** $Id: lua.c,v 1.123 2003/05/07 16:02:16 roberto Exp roberto $
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 */
@@ -117,10 +117,9 @@ static void l_message (const char *pname, const char *msg) {
 
 
 static int report (int status) {
-  const char *msg;
-  if (status) {
-    msg = lua_tostring(L, -1);
-    if (msg == NULL) msg = "(error with no message)";
+  if (status && !lua_isnil(L, -1)) {
+    const char *msg = lua_tostring(L, -1);
+    if (msg == NULL) msg = "(error object is not a string)";
     l_message(progname, msg);
     lua_pop(L, 1);
   }