FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Function 'luaK_semerror' made vararg · lua/lua@50fd8d0 · GitHub

/ lua Public

Commit 50fd8d0

Browse files
committed
Function 'luaK_semerror' made vararg
All calls to 'luaK_semerror' were using 'luaO_pushfstring' to create the error messages.
1 parent 3dbb1a4 commit 50fd8d0

3 files changed

Lines changed: 21 additions & 20 deletions

File tree

‎lcode.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ static int codesJ (FuncState *fs, OpCode o, int sj, int k);
4040

4141

4242
/* 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);
4451
ls->t.token = 0; /* remove "near <token>" from final message */
4552
luaX_syntaxerror(ls, msg);
4653
}

‎lcode.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,
9797
int ra, int asize, int hsize);
9898
LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
9999
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, ...);
101101

102102

103103
#endif

‎lparser.c‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,9 @@ static void check_readonly (LexState *ls, expdesc *e) {
306306
default:
307307
return; /* other cases cannot be read-only */
308308
}
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));
314312
}
315313

316314

@@ -523,9 +521,9 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
523521
static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) {
524522
TString *tsname = getlocalvardesc(ls->fs, gt->nactvar)->vd.name;
525523
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 */
529527
}
530528

531529

@@ -677,11 +675,10 @@ static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {
677675
** generates an error for an undefined 'goto'.
678676
*/
679677
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);
682678
/* breaks are checked when created, cannot be undefined */
683679
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);
685682
}
686683

687684

@@ -1479,11 +1476,9 @@ static void breakstat (LexState *ls, int line) {
14791476
*/
14801477
static void checkrepeated (LexState *ls, TString *name) {
14811478
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 */
14871482
}
14881483

14891484

@@ -1718,8 +1713,7 @@ static lu_byte getlocalattribute (LexState *ls) {
17181713
else if (strcmp(attr, "close") == 0)
17191714
return RDKTOCLOSE; /* to-be-closed variable */
17201715
else
1721-
luaK_semerror(ls,
1722-
luaO_pushfstring(ls->L, "unknown attribute '%s'", attr));
1716+
luaK_semerror(ls, "unknown attribute '%s'", attr);
17231717
}
17241718
return VDKREG; /* regular variable */
17251719
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL