Browse Source

better error message for (deprecated) "%global"

Roberto Ierusalimschy 22 years ago
parent
commit
6b6bc532a4
3 changed files with 21 additions and 9 deletions
  1. 8 3
      llex.c
  2. 2 1
      llex.h
  3. 11 5
      lparser.c

+ 8 - 3
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 1.116 2002/10/23 19:08:13 roberto Exp roberto $
+** $Id: llex.c,v 1.117 2002/12/04 17:38:31 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -59,15 +59,20 @@ void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) {
 }
 
 
-static void luaX_error (LexState *ls, const char *s, const char *token) {
+void luaX_errorline (LexState *ls, const char *s, const char *token, int line) {
   lua_State *L = ls->L;
   char buff[MAXSRC];
   luaO_chunkid(buff, getstr(ls->source), MAXSRC);
-  luaO_pushfstring(L, "%s:%d: %s near `%s'", buff, ls->linenumber, s, token); 
+  luaO_pushfstring(L, "%s:%d: %s near `%s'", buff, line, s, token); 
   luaD_throw(L, LUA_ERRSYNTAX);
 }
 
 
+static void luaX_error (LexState *ls, const char *s, const char *token) {
+  luaX_errorline(ls, s, token, ls->linenumber);
+}
+
+
 void luaX_syntaxerror (LexState *ls, const char *msg) {
   const char *lasttoken;
   switch (ls->t.token) {

+ 2 - 1
llex.h

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.h,v 1.45 2002/10/08 18:46:08 roberto Exp roberto $
+** $Id: llex.h,v 1.46 2002/11/22 16:35:20 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -68,6 +68,7 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
 int luaX_lex (LexState *LS, SemInfo *seminfo);
 void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
 void luaX_syntaxerror (LexState *ls, const char *s);
+void luaX_errorline (LexState *ls, const char *s, const char *token, int line);
 const char *luaX_token2str (LexState *ls, int token);
 
 

+ 11 - 5
lparser.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.c,v 1.205 2003/02/11 10:49:53 roberto Exp roberto $
+** $Id: lparser.c,v 1.206 2003/02/18 16:02:56 roberto Exp roberto $
 ** Lua Parser
 ** See Copyright Notice in lua.h
 */
@@ -240,8 +240,10 @@ static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
 }
 
 
-static void singlevar (LexState *ls, expdesc *var, int base) {
-  singlevaraux(ls->fs, str_checkname(ls), var, base);
+static TString *singlevar (LexState *ls, expdesc *var, int base) {
+  TString *varname = str_checkname(ls);
+  singlevaraux(ls->fs, varname, var, base);
+  return varname;
 }
 
 
@@ -645,9 +647,13 @@ static void prefixexp (LexState *ls, expdesc *v) {
     }
 #ifdef LUA_COMPATUPSYNTAX
     case '%': {  /* for compatibility only */
+      TString *varname;
+      int line = ls->linenumber;
       next(ls);  /* skip `%' */
-      singlevar(ls, v, 1);
-      check_condition(ls, v->k == VUPVAL, "global upvalues are obsolete");
+      varname = singlevar(ls, v, 1);
+      if (v->k != VUPVAL)
+        luaX_errorline(ls, "global upvalues are obsolete",
+                           getstr(varname), line);
       return;
     }
 #endif