| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3dbb1a4 commit 50fd8d0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,7 +40,14 @@ static int codesJ (FuncState *fs, OpCode o, int sj, int k); | |||
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | 42 | /* semantic error */ | |
| 43 | - l_noret luaK_semerror (LexState *ls, const char *msg) { | ||
| 43 | + l_noret luaK_semerror (LexState *ls, const char *fmt, ...) { | ||
| 44 | + const char *msg; | ||
| 45 | + va_list argp; | ||
| 46 | + va_start(argp, fmt); | ||
| 47 | + msg = luaO_pushvfstring(ls->L, fmt, argp); | ||
| 48 | + va_end(argp); | ||
| 49 | + if (msg == NULL) /* error? */ | ||
| 50 | + luaD_throw(ls->L, LUA_ERRMEM); | ||
| 44 | 51 | ls->t.token = 0; /* remove "near <token>" from final message */ | |
| 45 | 52 | luaX_syntaxerror(ls, msg); | |
| 46 | 53 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,7 +97,7 @@ LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc, | |||
| 97 | 97 | int ra, int asize, int hsize); | |
| 98 | 98 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); | |
| 99 | 99 | LUAI_FUNC void luaK_finish (FuncState *fs); | |
| 100 | - LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg); | ||
| 100 | + LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *fmt, ...); | ||
| 101 | 101 | ||
| 102 | 102 | ||
| 103 | 103 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -306,11 +306,9 @@ static void check_readonly (LexState *ls, expdesc *e) { | |||
| 306 | 306 | default: | |
| 307 | 307 | return; /* other cases cannot be read-only */ | |
| 308 | 308 | } | |
| 309 | - if (varname) { | ||
| 310 | - const char *msg = luaO_pushfstring(ls->L, | ||
| 311 | - "attempt to assign to const variable '%s'", getstr(varname)); | ||
| 312 | - luaK_semerror(ls, msg); /* error */ | ||
| 313 | - } | ||
| 309 | + if (varname) | ||
| 310 | + luaK_semerror(ls, "attempt to assign to const variable '%s'", | ||
| 311 | + getstr(varname)); | ||
| 314 | 312 | } | |
| 315 | 313 | ||
| 316 | 314 | ||
@@ -523,9 +521,9 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { | |||
| 523 | 521 | static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) { | |
| 524 | 522 | TString *tsname = getlocalvardesc(ls->fs, gt->nactvar)->vd.name; | |
| 525 | 523 | const char *varname = getstr(tsname); | |
| 526 | - const char *msg = "<goto %s> at line %d jumps into the scope of local '%s'"; | ||
| 527 | - msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line, varname); | ||
| 528 | - luaK_semerror(ls, msg); /* raise the error */ | ||
| 524 | + luaK_semerror(ls, | ||
| 525 | + "<goto %s> at line %d jumps into the scope of local '%s'", | ||
| 526 | + getstr(gt->name), gt->line, varname); /* raise the error */ | ||
| 529 | 527 | } | |
| 530 | 528 | ||
| 531 | 529 | ||
@@ -677,11 +675,10 @@ static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) { | |||
| 677 | 675 | ** generates an error for an undefined 'goto'. | |
| 678 | 676 | */ | |
| 679 | 677 | static l_noret undefgoto (LexState *ls, Labeldesc *gt) { | |
| 680 | - const char *msg = "no visible label '%s' for <goto> at line %d"; | ||
| 681 | - msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line); | ||
| 682 | 678 | /* breaks are checked when created, cannot be undefined */ | |
| 683 | 679 | lua_assert(!eqstr(gt->name, luaS_newliteral(ls->L, "break"))); | |
| 684 | - luaK_semerror(ls, msg); | ||
| 680 | + luaK_semerror(ls, "no visible label '%s' for <goto> at line %d", | ||
| 681 | + getstr(gt->name), gt->line); | ||
| 685 | 682 | } | |
| 686 | 683 | ||
| 687 | 684 | ||
@@ -1479,11 +1476,9 @@ static void breakstat (LexState *ls, int line) { | |||
| 1479 | 1476 | */ | |
| 1480 | 1477 | static void checkrepeated (LexState *ls, TString *name) { | |
| 1481 | 1478 | Labeldesc *lb = findlabel(ls, name, ls->fs->firstlabel); | |
| 1482 | - if (l_unlikely(lb != NULL)) { /* already defined? */ | ||
| 1483 | - const char *msg = "label '%s' already defined on line %d"; | ||
| 1484 | - msg = luaO_pushfstring(ls->L, msg, getstr(name), lb->line); | ||
| 1485 | - luaK_semerror(ls, msg); /* error */ | ||
| 1486 | - } | ||
| 1479 | + if (l_unlikely(lb != NULL)) /* already defined? */ | ||
| 1480 | + luaK_semerror(ls, "label '%s' already defined on line %d", | ||
| 1481 | + getstr(name), lb->line); /* error */ | ||
| 1487 | 1482 | } | |
| 1488 | 1483 | ||
| 1489 | 1484 | ||
@@ -1718,8 +1713,7 @@ static lu_byte getlocalattribute (LexState *ls) { | |||
| 1718 | 1713 | else if (strcmp(attr, "close") == 0) | |
| 1719 | 1714 | return RDKTOCLOSE; /* to-be-closed variable */ | |
| 1720 | 1715 | else | |
| 1721 | - luaK_semerror(ls, | ||
| 1722 | - luaO_pushfstring(ls->L, "unknown attribute '%s'", attr)); | ||
| 1716 | + luaK_semerror(ls, "unknown attribute '%s'", attr); | ||
| 1723 | 1717 | } | |
| 1724 | 1718 | return VDKREG; /* regular variable */ | |
| 1725 | 1719 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments