Browse Source

error codes as strings for dofile and dostring

Roberto Ierusalimschy 25 years ago
parent
commit
5d69960734
1 changed files with 4 additions and 2 deletions
  1. 4 2
      lbaselib.c

+ 4 - 2
lbaselib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: $
+** $Id: lbaselib.c,v 1.1 2000/09/05 19:33:56 roberto Exp roberto $
 ** Basic library
 ** See Copyright Notice in lua.h
 */
@@ -217,6 +217,8 @@ static int luaB_next (lua_State *L) {
 
 
 static int passresults (lua_State *L, int status, int oldtop) {
+  static const char *const errornames[] =
+    {"OK", "RUN-TIME ERROR", "FILE ERROR", "SYNTAX ERROR", "MEMORY ERROR"};
   if (status == 0) {
     int nresults = lua_gettop(L) - oldtop;
     if (nresults > 0)
@@ -228,7 +230,7 @@ static int passresults (lua_State *L, int status, int oldtop) {
   }
   else {  /* error */
     lua_pushnil(L);
-    lua_pushnumber(L, status);  /* error code */
+    lua_pushstring(L, errornames[status]);  /* error code */
     return 2;
   }
 }