Переглянути джерело

new format for error messages

Roberto Ierusalimschy 23 роки тому
батько
коміт
b7a0503c1d
15 змінених файлів з 113 додано та 96 видалено
  1. 4 3
      lapi.c
  2. 8 1
      lauxlib.c
  3. 11 15
      ldblib.c
  4. 23 7
      ldebug.c
  5. 2 1
      ldebug.h
  6. 6 11
      ldo.c
  7. 1 2
      ldo.h
  8. 2 3
      llex.c
  9. 4 3
      lmem.c
  10. 10 20
      lobject.c
  11. 1 2
      lobject.h
  12. 5 4
      ltable.c
  13. 18 6
      lua.c
  14. 10 10
      lundump.c
  15. 8 8
      lvm.c

+ 4 - 3
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 1.189 2002/05/06 19:05:10 roberto Exp roberto $
+** $Id: lapi.c,v 1.190 2002/05/07 17:36:56 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -11,6 +11,7 @@
 #include "lua.h"
 
 #include "lapi.h"
+#include "ldebug.h"
 #include "ldo.h"
 #include "lfunc.h"
 #include "lgc.h"
@@ -521,8 +522,8 @@ LUA_API void lua_setmetatable (lua_State *L, int objindex) {
       uvalue(obj)->uv.metatable = hvalue(mt);
       break;
     default:
-      luaO_verror(L, "cannot change the meta table of a %s",
-                  luaT_typenames[ttype(obj)]);
+      luaG_runerror(L, "cannot change the meta table of a %s",
+                       luaT_typenames[ttype(obj)]);
   }
   lua_unlock(L);
 }

+ 8 - 1
lauxlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.c,v 1.68 2002/05/06 19:05:10 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.69 2002/05/07 17:36:56 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -151,10 +151,17 @@ LUALIB_API void luaL_vstr (lua_State *L, const char *fmt, ...) {
 
 
 LUALIB_API int luaL_verror (lua_State *L, const char *fmt, ...) {
+  lua_Debug ar;
   va_list argp;
   va_start(argp, fmt);
   lua_vpushstr(L, fmt, argp);
   va_end(argp);
+  if (lua_getstack(L, 1, &ar)) {  /* check calling function */
+    lua_getinfo(L, "Snl", &ar);
+    if (ar.currentline > 0)
+      luaL_vstr(L, "%s:%d: %s",
+                   ar.short_src, ar.currentline, lua_tostring(L, -1));
+  }
   return lua_errorobj(L);
 }
 

+ 11 - 15
ldblib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldblib.c,v 1.50 2002/05/06 19:05:10 roberto Exp roberto $
+** $Id: ldblib.c,v 1.51 2002/05/07 17:36:56 roberto Exp roberto $
 ** Interface from Lua to its debug API
 ** See Copyright Notice in lua.h
 */
@@ -54,8 +54,7 @@ static int getinfo (lua_State *L) {
     switch (*options) {
       case 'S':
         settabss(L, "source", ar.source);
-        if (ar.source)
-          settabss(L, "short_src", ar.short_src);
+        settabss(L, "short_src", ar.short_src);
         settabsi(L, "linedefined", ar.linedefined);
         settabss(L, "what", ar.what);
         break;
@@ -205,31 +204,28 @@ static int errorfb (lua_State *L) {
       firstpart = 0;
       continue;
     }
-    sprintf(buff, "%4d:  ", level-1);
+    sprintf(buff, "%4d-  ", level-1);
     lua_pushstring(L, buff);
     lua_getinfo(L, "Snl", &ar);
+    luaL_vstr(L, "%s:", ar.short_src);
+    if (ar.currentline > 0)
+      luaL_vstr(L, "%d:", ar.currentline);
     switch (*ar.namewhat) {
-      case 'g':  case 'l':  /* global, local */
-        luaL_vstr(L, "function `%s'", ar.name);
-        break;
+      case 'g':  /* global */ 
+      case 'l':  /* local */
       case 'f':  /* field */
       case 'm':  /* method */
-        luaL_vstr(L, "method `%s'", ar.name);
+        luaL_vstr(L, " in function `%s'", ar.name);
         break;
       default: {
         if (*ar.what == 'm')  /* main? */
-          luaL_vstr(L, "main of %s", ar.short_src);
+          luaL_vstr(L, " in main chunk");
         else if (*ar.what == 'C')  /* C function? */
           luaL_vstr(L, "%s", ar.short_src);
         else
-          luaL_vstr(L, "function <%d:%s>", ar.linedefined, ar.short_src);
-        ar.source = NULL;  /* do not print source again */
+          luaL_vstr(L, " in function <%s:%d>", ar.short_src, ar.linedefined);
       }
     }
-    if (ar.currentline > 0)
-      luaL_vstr(L, " at line %d", ar.currentline);
-    if (ar.source)
-      luaL_vstr(L, " [%s]", ar.short_src);
     lua_pushliteral(L, "\n");
     lua_concat(L, lua_gettop(L));
   }

+ 23 - 7
ldebug.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.c,v 1.114 2002/05/13 13:09:00 roberto Exp roberto $
+** $Id: ldebug.c,v 1.115 2002/05/14 17:52:22 roberto Exp roberto $
 ** Debug Interface
 ** See Copyright Notice in lua.h
 */
@@ -144,11 +144,11 @@ static void funcinfo (lua_State *L, lua_Debug *ar, StkId func) {
   if (ttype(func) == LUA_TFUNCTION)
     cl = clvalue(func);
   else {
-    luaD_runerror(L, "value for `lua_getinfo' is not a function");
+    luaG_runerror(L, "value for `lua_getinfo' is not a function");
     cl = NULL;  /* to avoid warnings */
   }
   if (cl->c.isC) {
-    ar->source = "=C";
+    ar->source = "=[C]";
     ar->linedefined = -1;
     ar->what = "C";
   }
@@ -481,10 +481,10 @@ void luaG_typeerror (lua_State *L, const TObject *o, const char *op) {
   if (isinstack(L->ci, o))
     kind = getobjname(L, L->ci, o - L->ci->base, &name);
   if (kind)
-    luaO_verror(L, "attempt to %s %s `%s' (a %s value)",
+    luaG_runerror(L, "attempt to %s %s `%s' (a %s value)",
                 op, kind, name, t);
   else
-    luaO_verror(L, "attempt to %s a %s value", op, t);
+    luaG_runerror(L, "attempt to %s a %s value", op, t);
 }
 
 
@@ -507,8 +507,24 @@ void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) {
   const char *t1 = luaT_typenames[ttype(p1)];
   const char *t2 = luaT_typenames[ttype(p2)];
   if (t1[2] == t2[2])
-    luaO_verror(L, "attempt to compare two %s values", t1);
+    luaG_runerror(L, "attempt to compare two %s values", t1);
   else
-    luaO_verror(L, "attempt to compare %s with %s", t1, t2);
+    luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
+}
+
+
+void luaG_runerror (lua_State *L, const char *fmt, ...) {
+  const char *msg;
+  va_list argp;
+  va_start(argp, fmt);
+  msg = luaO_vpushstr(L, fmt, argp);
+  va_end(argp);
+  if (isLmark(L->ci)) {
+    char buff[LUA_IDSIZE];
+    int line = currentline(L, L->ci);
+    luaO_chunkid(buff, getstr(getluaproto(L->ci)->source), LUA_IDSIZE);
+    msg = luaO_pushstr(L, "%s:%d: %s", buff, line, msg);
+  }
+  luaD_error(L, msg, LUA_ERRRUN);
 }
 

+ 2 - 1
ldebug.h

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.h,v 1.19 2002/04/10 12:11:07 roberto Exp roberto $
+** $Id: ldebug.h,v 1.20 2002/05/02 13:06:20 roberto Exp roberto $
 ** Auxiliary functions from Debug Interface module
 ** See Copyright Notice in lua.h
 */
@@ -20,6 +20,7 @@ void luaG_typeerror (lua_State *L, const TObject *o, const char *opname);
 void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
 void luaG_aritherror (lua_State *L, StkId p1, const TObject *p2);
 void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2);
+void luaG_runerror (lua_State *L, const char *fmt, ...);
 int luaG_checkcode (const Proto *pt);
 
 

+ 6 - 11
ldo.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.c,v 1.173 2002/05/01 20:40:42 roberto Exp roberto $
+** $Id: ldo.c,v 1.174 2002/05/07 17:36:56 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -113,7 +113,7 @@ static void luaD_growCI (lua_State *L) {
   else {
     luaD_reallocCI(L, 2*L->size_ci);
     if (L->size_ci > LUA_MAXCALLS)
-      luaD_runerror(L, "stack overflow");
+      luaG_runerror(L, "stack overflow");
   }
   L->ci++;
 }
@@ -279,7 +279,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
     firstResult = luaV_execute(L);  /* call it */
     if (firstResult == NULL) {
       luaD_poscall(L, 0, L->top);
-      luaD_runerror(L, "attempt to `yield' across tag-method/C-call boundary");
+      luaG_runerror(L, "attempt to `yield' across tag-method/C-call boundary");
     }
   }
   luaD_poscall(L, nResults, firstResult);
@@ -335,9 +335,9 @@ LUA_API int lua_resume (lua_State *L, lua_State *co) {
   lua_lock(L);
   ci = co->ci;
   if (ci == co->base_ci)  /* no activation record? ?? */
-    luaD_runerror(L, "thread is dead - cannot be resumed");
+    luaG_runerror(L, "thread is dead - cannot be resumed");
   if (co->errorJmp != NULL)  /* ?? */
-    luaD_runerror(L, "thread is active - cannot be resumed");
+    luaG_runerror(L, "thread is active - cannot be resumed");
   if (L->errorJmp) {
     setobj(&ud.err, L->errorJmp->err);
   }
@@ -359,7 +359,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) {
   lua_lock(L);
   ci = L->ci;
   if (ci_func(ci-1)->c.isC)
-    luaD_runerror(L, "cannot `yield' a C function");
+    luaG_runerror(L, "cannot `yield' a C function");
   ci->yield_results = nresults;
   lua_unlock(L);
   return -1;
@@ -492,11 +492,6 @@ void luaD_error (lua_State *L, const char *s, int errcode) {
 }
 
 
-void luaD_runerror (lua_State *L, const char *s) {
-  luaD_error(L, s, LUA_ERRRUN);
-}
-
-
 int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud) {
   struct lua_longjmp lj;
   lj.ci = L->ci;

+ 1 - 2
ldo.h

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.h,v 1.43 2002/04/22 14:40:50 roberto Exp roberto $
+** $Id: ldo.h,v 1.44 2002/05/01 20:40:42 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -43,7 +43,6 @@ void luaD_growstack (lua_State *L, int n);
 
 void luaD_error (lua_State *L, const char *s, int errcode);
 void luaD_errorobj (lua_State *L, const TObject *s, int errcode);
-void luaD_runerror (lua_State *L, const char *s);
 int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud);
 
 

+ 2 - 3
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 1.99 2002/03/08 19:25:24 roberto Exp roberto $
+** $Id: llex.c,v 1.100 2002/05/07 17:36:56 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -61,8 +61,7 @@ static void luaX_error (LexState *ls, const char *s, const char *token) {
   lua_State *L = ls->L;
   char buff[MAXSRC];
   luaO_chunkid(buff, getstr(ls->source), MAXSRC);
-  luaO_pushstr(L, "%s;\n  last token read: `%s' at line %d in %s",
-                        s, token, ls->linenumber, buff);
+  luaO_pushstr(L, "%s:%d: %s near `%s'", buff, ls->linenumber, s, token); 
   luaD_errorobj(L, L->top - 1, LUA_ERRSYNTAX);
 }
 

+ 4 - 3
lmem.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lmem.c,v 1.53 2002/04/22 14:40:23 roberto Exp roberto $
+** $Id: lmem.c,v 1.54 2002/05/01 20:40:42 roberto Exp roberto $
 ** Interface to Memory Manager
 ** See Copyright Notice in lua.h
 */
@@ -9,6 +9,7 @@
 
 #include "lua.h"
 
+#include "ldebug.h"
 #include "ldo.h"
 #include "lmem.h"
 #include "lobject.h"
@@ -34,7 +35,7 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems,
   else if (*size >= limit/2) {  /* cannot double it? */
     if (*size < limit - MINSIZEARRAY)  /* try something smaller... */
       newsize = limit;  /* still have at least MINSIZEARRAY free places */
-    else luaD_runerror(L, errormsg);
+    else luaG_runerror(L, errormsg);
   }
   newblock = luaM_realloc(L, block,
                           cast(lu_mem, *size)*cast(lu_mem, size_elems),
@@ -53,7 +54,7 @@ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
     block = NULL;
   }
   else if (size >= MAX_SIZET)
-    luaD_runerror(L, "memory allocation error: block too big");
+    luaG_runerror(L, "memory allocation error: block too big");
   else {
     block = l_realloc(block, oldsize, size);
     if (block == NULL) {

+ 10 - 20
lobject.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.c,v 1.78 2002/05/06 15:51:41 roberto Exp roberto $
+** $Id: lobject.c,v 1.79 2002/05/07 17:36:56 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -100,7 +100,8 @@ static void pushstr (lua_State *L, const char *str) {
 
 /* this function handles only `%d', `%c', %f, and `%s' formats */
 const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp) {
-  int n = 0;
+  int n = 1;
+  pushstr(L, "");
   for (;;) {
     const char *e = strchr(fmt, '%');
     if (e == NULL) break;
@@ -150,47 +151,36 @@ const char *luaO_pushstr (lua_State *L, const char *fmt, ...) {
 }
 
 
-void luaO_verror (lua_State *L, const char *fmt, ...) {
-  const char *msg;
-  va_list argp;
-  va_start(argp, fmt);
-  msg = luaO_vpushstr(L, fmt, argp);
-  va_end(argp);
-  luaD_runerror(L, msg);
-}
-
-
 void luaO_chunkid (char *out, const char *source, int bufflen) {
   if (*source == '=') {
     strncpy(out, source+1, bufflen);  /* remove first char */
     out[bufflen-1] = '\0';  /* ensures null termination */
   }
-  else {  /* out = "file `source'", or "file `...source'" */
+  else {  /* out = "source", or "...source" */
     if (*source == '@') {
       int l;
       source++;  /* skip the `@' */
-      bufflen -= sizeof(" file `...' ");
+      bufflen -= sizeof(" `...' ");
       l = strlen(source);
-      strcpy(out, "file `");
+      strcpy(out, "");
       if (l>bufflen) {
         source += (l-bufflen);  /* get last part of file name */
         strcat(out, "...");
       }
       strcat(out, source);
-      strcat(out, "'");
     }
-    else {
+    else {  /* out = [string "string"] */
       int len = strcspn(source, "\n");  /* stop at first newline */
-      bufflen -= sizeof(" string \"...\" ");
+      bufflen -= sizeof(" [string \"...\"] ");
       if (len > bufflen) len = bufflen;
-      strcpy(out, "string \"");
+      strcpy(out, "[string \"");
       if (source[len] != '\0') {  /* must truncate? */
         strncat(out, source, len);
         strcat(out, "...");
       }
       else
         strcat(out, source);
-      strcat(out, "\"");
+      strcat(out, "\"]");
     }
   }
 }

+ 1 - 2
lobject.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.h,v 1.130 2002/05/06 15:51:41 roberto Exp roberto $
+** $Id: lobject.h,v 1.131 2002/05/07 17:36:56 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -252,7 +252,6 @@ int luaO_str2d (const char *s, lua_Number *result);
 
 const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp);
 const char *luaO_pushstr (lua_State *L, const char *fmt, ...);
-void luaO_verror (lua_State *L, const char *fmt, ...);
 void luaO_chunkid (char *out, const char *source, int len);
 
 

+ 5 - 4
ltable.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.c,v 1.106 2002/05/08 17:34:00 roberto Exp roberto $
+** $Id: ltable.c,v 1.107 2002/05/13 13:38:59 roberto Exp roberto $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -25,6 +25,7 @@
 
 #include "lua.h"
 
+#include "ldebug.h"
 #include "ldo.h"
 #include "lmem.h"
 #include "lobject.h"
@@ -111,7 +112,7 @@ static int luaH_index (lua_State *L, Table *t, const TObject *key) {
   else {
     const TObject *v = luaH_get(t, key);
     if (v == &luaO_nilobject)
-      luaD_runerror(L, "invalid key for `next'");
+      luaG_runerror(L, "invalid key for `next'");
     i = cast(int, (cast(const lu_byte *, v) -
                    cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node));
     return i + t->sizearray;  /* hash elements are numbered after array ones */
@@ -214,7 +215,7 @@ static void setnodevector (lua_State *L, Table *t, int lsize) {
   int i;
   int size = twoto(lsize);
   if (lsize > MAXBITS)
-    luaD_runerror(L, "table overflow");
+    luaG_runerror(L, "table overflow");
   if (lsize == 0) {  /* no elements to hash part? */
     t->node = G(L)->dummynode;  /* use common `dummynode' */
     lua_assert(ttype(key(t->node)) == LUA_TNIL);  /* assert invariants: */
@@ -449,7 +450,7 @@ void luaH_set (lua_State *L, Table *t, const TObject *key, const TObject *val) {
     settableval(p, val);
   }
   else {
-    if (ttype(key) == LUA_TNIL) luaD_runerror(L, "table index is nil");
+    if (ttype(key) == LUA_TNIL) luaG_runerror(L, "table index is nil");
     newkey(L, t, key, val);
   }
   t->flags = 0;

+ 18 - 6
lua.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.c,v 1.84 2002/04/23 14:59:22 roberto Exp roberto $
+** $Id: lua.c,v 1.85 2002/05/01 20:40:42 roberto Exp roberto $
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 */
@@ -71,7 +71,7 @@ static void report (int status) {
   else {
     const char *msg = lua_tostring(L, -1);
     if (msg == NULL) msg = "(no message)";
-    fprintf(stderr, "error: %s\n", msg);
+    fprintf(stderr, "%s\n", msg);
     lua_pop(L, 1);
   }
 }
@@ -152,8 +152,8 @@ static int file_input (const char *name) {
 }
 
 
-static int dostring (const char *s) {
-  int status = lua_loadbuffer(L, s, strlen(s), s);
+static int dostring (const char *s, const char *name) {
+  int status = lua_loadbuffer(L, s, strlen(s), name);
   if (status == 0) status = lcall(1);
   report(status);
   return status;
@@ -198,7 +198,7 @@ static const char *get_prompt (int firstline) {
 
 static int incomplete (int status) {
   if (status == LUA_ERRSYNTAX &&
-         strstr(lua_tostring(L, -1), "last token read: `<eof>'") != NULL) {
+         strstr(lua_tostring(L, -1), "near `<eof>'") != NULL) {
     lua_pop(L, 1);
     return 1;
   }
@@ -289,7 +289,7 @@ static int handle_argv (char *argv[], int *toclose) {
               print_usage();
               return EXIT_FAILURE;
             }
-            if (dostring(argv[i]) != 0) {
+            if (dostring(argv[i], "=prog. argument") != 0) {
               fprintf(stderr, "%s: error running argument `%.99s'\n",
                       LUA_PROGNAME, argv[i]);
               return EXIT_FAILURE;
@@ -340,6 +340,16 @@ static void openstdlibs (lua_State *l) {
 }
 
 
+static int handle_luainit (void) {
+  const char *init = getenv("LUA_INIT");
+  if (init == NULL) return 0;  /* status OK */
+  else if (init[0] == '@')
+    return file_input(init+1);
+  else
+    return dostring(init, "=LUA_INIT");
+}
+
+
 int main (int argc, char *argv[]) {
   int status;
   int toclose = 0;
@@ -347,6 +357,8 @@ int main (int argc, char *argv[]) {
   L = lua_open();  /* create state */
   LUA_USERINIT(L);  /* open libraries */
   register_getargs(argv);  /* create `getargs' function */
+  status = handle_luainit();
+  if (status != 0) return status;
   status = handle_argv(argv+1, &toclose);
   if (toclose)
     lua_close(L);

+ 10 - 10
lundump.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lundump.c,v 1.45 2002/03/25 17:47:14 roberto Exp roberto $
+** $Id: lundump.c,v 1.46 2002/05/07 17:36:56 roberto Exp roberto $
 ** load pre-compiled Lua chunks
 ** See Copyright Notice in lua.h
 */
@@ -27,7 +27,7 @@ static const char* ZNAME (ZIO* Z)
 
 static void unexpectedEOZ (lua_State* L, ZIO* Z)
 {
- luaO_verror(L,"unexpected end of file in `%s'",ZNAME(Z));
+ luaG_runerror(L,"unexpected end of file in `%s'",ZNAME(Z));
 }
 
 static int ezgetc (lua_State* L, ZIO* Z)
@@ -157,7 +157,7 @@ static void LoadConstants (lua_State* L, Proto* f, ZIO* Z, int swap)
 	tsvalue(o)=LoadString(L,Z,swap);
 	break;
    default:
-	luaO_verror(L,"bad constant type (%d) in `%s'",ttype(o),ZNAME(Z));
+	luaG_runerror(L,"bad constant type (%d) in `%s'",ttype(o),ZNAME(Z));
 	break;
   }
  }
@@ -181,7 +181,7 @@ static Proto* LoadFunction (lua_State* L, TString* p, ZIO* Z, int swap)
  LoadConstants(L,f,Z,swap);
  LoadCode(L,f,Z,swap);
 #ifndef TRUST_BINARIES
- if (!luaG_checkcode(f)) luaO_verror(L,"bad code in `%s'",ZNAME(Z));
+ if (!luaG_checkcode(f)) luaG_runerror(L,"bad code in `%s'",ZNAME(Z));
 #endif
  return f;
 }
@@ -191,14 +191,14 @@ static void LoadSignature (lua_State* L, ZIO* Z)
  const char* s=LUA_SIGNATURE;
  while (*s!=0 && ezgetc(L,Z)==*s)
   ++s;
- if (*s!=0) luaO_verror(L,"bad signature in `%s'",ZNAME(Z));
+ if (*s!=0) luaG_runerror(L,"bad signature in `%s'",ZNAME(Z));
 }
 
 static void TestSize (lua_State* L, int s, const char* what, ZIO* Z)
 {
  int r=LoadByte(L,Z);
  if (r!=s)
-  luaO_verror(L,"virtual machine mismatch in `%s':\n"
+  luaG_runerror(L,"virtual machine mismatch in `%s':\n"
 	"  size of %.20s is %d but read %d",ZNAME(Z),what,s,r);
 }
 
@@ -212,11 +212,11 @@ static int LoadHeader (lua_State* L, ZIO* Z)
  LoadSignature(L,Z);
  version=LoadByte(L,Z);
  if (version>VERSION)
-  luaO_verror(L,"`%s' too new:\n"
+  luaG_runerror(L,"`%s' too new:\n"
 	"  read version %d.%d; expected at most %d.%d",
 	ZNAME(Z),V(version),V(VERSION));
  if (version<VERSION0)			/* check last major change */
-  luaO_verror(L,"`%s' too old:\n"
+  luaG_runerror(L,"`%s' too old:\n"
 	"  read version %d.%d; expected at least %d.%d",
 	ZNAME(Z),V(version),V(VERSION));
  swap=(luaU_endianness()!=LoadByte(L,Z));	/* need to swap bytes? */
@@ -230,7 +230,7 @@ static int LoadHeader (lua_State* L, ZIO* Z)
  TESTSIZE(sizeof(lua_Number), "number");
  x=LoadNumber(L,Z,swap);
  if ((long)x!=(long)tx)		/* disregard errors in last bits of fraction */
-  luaO_verror(L,"unknown number format in `%s':\n"
+  luaG_runerror(L,"unknown number format in `%s':\n"
       "  read " LUA_NUMBER_FMT "; expected " LUA_NUMBER_FMT,
       ZNAME(Z),x,tx);
  return swap;
@@ -248,7 +248,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z)
 {
  Proto* f=LoadChunk(L,Z);
  if (zgetc(Z)!=EOZ)
-  luaO_verror(L,"`%s' apparently contains more than one chunk",ZNAME(Z));
+  luaG_runerror(L,"`%s' apparently contains more than one chunk",ZNAME(Z));
  return f;
 }
 

+ 8 - 8
lvm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lvm.c,v 1.230 2002/05/09 14:14:34 roberto Exp roberto $
+** $Id: lvm.c,v 1.231 2002/05/13 13:09:00 roberto Exp roberto $
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -134,7 +134,7 @@ void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
   if (ttype(tm) == LUA_TFUNCTION)
     callTMres(L, tm, t, key, res);
   else {
-    if (++loop == MAXTAGLOOP) luaD_runerror(L, "loop in gettable");
+    if (++loop == MAXTAGLOOP) luaG_runerror(L, "loop in gettable");
     t = tm;
     goto init;  /* return luaV_gettable(L, tm, key, res); */
   }
@@ -164,7 +164,7 @@ void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
   if (ttype(tm) == LUA_TFUNCTION)
     callTM(L, tm, t, key, val);
   else {
-    if (++loop == MAXTAGLOOP) luaD_runerror(L, "loop in settable");
+    if (++loop == MAXTAGLOOP) luaG_runerror(L, "loop in settable");
     t = tm;
     goto init;  /* luaV_settable(L, tm, key, val); */
   }
@@ -251,7 +251,7 @@ void luaV_strconc (lua_State *L, int total, int last) {
         tl += tsvalue(top-n-1)->tsv.len;
         n++;
       }
-      if (tl > MAX_SIZET) luaD_runerror(L, "string size overflow");
+      if (tl > MAX_SIZET) luaG_runerror(L, "string size overflow");
       buffer = luaO_openspace(L, tl, char);
       tl = 0;
       for (i=n; i>0; i--) {  /* concat all strings */
@@ -276,7 +276,7 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) {
     setsvalue(&o, luaS_newliteral(L, "pow"));
     luaV_gettable(L, gt(L), &o, &f);
     if (ttype(&f) != LUA_TFUNCTION)
-      luaD_runerror(L, "`pow' (for `^' operator) is not a function");
+      luaG_runerror(L, "`pow' (for `^' operator) is not a function");
     callTMres(L, &f, b, c, ra);
   }
   else
@@ -527,11 +527,11 @@ StkId luaV_execute (lua_State *L) {
         const TObject *plimit = ra+1;
         const TObject *pstep = ra+2;
         if (ttype(ra) != LUA_TNUMBER)
-          luaD_runerror(L, "`for' initial value must be a number");
+          luaG_runerror(L, "`for' initial value must be a number");
         if (!tonumber(plimit, ra+1))
-          luaD_runerror(L, "`for' limit must be a number");
+          luaG_runerror(L, "`for' limit must be a number");
         if (!tonumber(pstep, ra+2))
-          luaD_runerror(L, "`for' step must be a number");
+          luaG_runerror(L, "`for' step must be a number");
         step = nvalue(pstep);
         index = nvalue(ra) + step;  /* increment index */
         limit = nvalue(plimit);