aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-02-28 14:19:47 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-02-28 14:19:47 -0300
commit6b6bc532a4f5e335540e6f19914cfe8435d064ed (patch)
treea7d456a86bf86ef6d6e1333d7372f17ad9562773
parentea16ee41a8b0e6fe2c8f77e901a7d99173065beb (diff)
downloadlua-6b6bc532a4f5e335540e6f19914cfe8435d064ed.tar.gz
lua-6b6bc532a4f5e335540e6f19914cfe8435d064ed.tar.bz2
lua-6b6bc532a4f5e335540e6f19914cfe8435d064ed.zip
better error message for (deprecated) "%global"
-rw-r--r--llex.c11
-rw-r--r--llex.h3
-rw-r--r--lparser.c16
3 files changed, 21 insertions, 9 deletions
diff --git a/llex.c b/llex.c
index 4b67b2d1..c1df127e 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.116 2002/10/23 19:08:13 roberto Exp roberto $ 2** $Id: llex.c,v 1.117 2002/12/04 17:38:31 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -59,15 +59,20 @@ void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) {
59} 59}
60 60
61 61
62static void luaX_error (LexState *ls, const char *s, const char *token) { 62void luaX_errorline (LexState *ls, const char *s, const char *token, int line) {
63 lua_State *L = ls->L; 63 lua_State *L = ls->L;
64 char buff[MAXSRC]; 64 char buff[MAXSRC];
65 luaO_chunkid(buff, getstr(ls->source), MAXSRC); 65 luaO_chunkid(buff, getstr(ls->source), MAXSRC);
66 luaO_pushfstring(L, "%s:%d: %s near `%s'", buff, ls->linenumber, s, token); 66 luaO_pushfstring(L, "%s:%d: %s near `%s'", buff, line, s, token);
67 luaD_throw(L, LUA_ERRSYNTAX); 67 luaD_throw(L, LUA_ERRSYNTAX);
68} 68}
69 69
70 70
71static void luaX_error (LexState *ls, const char *s, const char *token) {
72 luaX_errorline(ls, s, token, ls->linenumber);
73}
74
75
71void luaX_syntaxerror (LexState *ls, const char *msg) { 76void luaX_syntaxerror (LexState *ls, const char *msg) {
72 const char *lasttoken; 77 const char *lasttoken;
73 switch (ls->t.token) { 78 switch (ls->t.token) {
diff --git a/llex.h b/llex.h
index 2df59d0b..00c73c77 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.h,v 1.45 2002/10/08 18:46:08 roberto Exp roberto $ 2** $Id: llex.h,v 1.46 2002/11/22 16:35:20 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -68,6 +68,7 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
68int luaX_lex (LexState *LS, SemInfo *seminfo); 68int luaX_lex (LexState *LS, SemInfo *seminfo);
69void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); 69void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
70void luaX_syntaxerror (LexState *ls, const char *s); 70void luaX_syntaxerror (LexState *ls, const char *s);
71void luaX_errorline (LexState *ls, const char *s, const char *token, int line);
71const char *luaX_token2str (LexState *ls, int token); 72const char *luaX_token2str (LexState *ls, int token);
72 73
73 74
diff --git a/lparser.c b/lparser.c
index c5b5df85..722c5bb8 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.205 2003/02/11 10:49:53 roberto Exp roberto $ 2** $Id: lparser.c,v 1.206 2003/02/18 16:02:56 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -240,8 +240,10 @@ static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
240} 240}
241 241
242 242
243static void singlevar (LexState *ls, expdesc *var, int base) { 243static TString *singlevar (LexState *ls, expdesc *var, int base) {
244 singlevaraux(ls->fs, str_checkname(ls), var, base); 244 TString *varname = str_checkname(ls);
245 singlevaraux(ls->fs, varname, var, base);
246 return varname;
245} 247}
246 248
247 249
@@ -645,9 +647,13 @@ static void prefixexp (LexState *ls, expdesc *v) {
645 } 647 }
646#ifdef LUA_COMPATUPSYNTAX 648#ifdef LUA_COMPATUPSYNTAX
647 case '%': { /* for compatibility only */ 649 case '%': { /* for compatibility only */
650 TString *varname;
651 int line = ls->linenumber;
648 next(ls); /* skip `%' */ 652 next(ls); /* skip `%' */
649 singlevar(ls, v, 1); 653 varname = singlevar(ls, v, 1);
650 check_condition(ls, v->k == VUPVAL, "global upvalues are obsolete"); 654 if (v->k != VUPVAL)
655 luaX_errorline(ls, "global upvalues are obsolete",
656 getstr(varname), line);
651 return; 657 return;
652 } 658 }
653#endif 659#endif