1
0
Fork 0
mirror of https://github.com/lua/lua.git synced 2025-07-05 04:34:06 +00:00

Function 'luaK_semerror' made vararg

All calls to 'luaK_semerror' were using 'luaO_pushfstring' to create
the error messages.
This commit is contained in:
Roberto Ierusalimschy 2025-04-17 14:58:55 -03:00
parent 3dbb1a4b89
commit 50fd8d03c3
3 changed files with 21 additions and 20 deletions

View file

@ -40,7 +40,14 @@ static int codesJ (FuncState *fs, OpCode o, int sj, int k);
/* semantic error */
l_noret luaK_semerror (LexState *ls, const char *msg) {
l_noret luaK_semerror (LexState *ls, const char *fmt, ...) {
const char *msg;
va_list argp;
va_start(argp, fmt);
msg = luaO_pushvfstring(ls->L, fmt, argp);
va_end(argp);
if (msg == NULL) /* error? */
luaD_throw(ls->L, LUA_ERRMEM);
ls->t.token = 0; /* remove "near <token>" from final message */
luaX_syntaxerror(ls, msg);
}

View file

@ -97,7 +97,7 @@ LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,
int ra, int asize, int hsize);
LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
LUAI_FUNC void luaK_finish (FuncState *fs);
LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg);
LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *fmt, ...);
#endif

View file

@ -306,11 +306,9 @@ static void check_readonly (LexState *ls, expdesc *e) {
default:
return; /* other cases cannot be read-only */
}
if (varname) {
const char *msg = luaO_pushfstring(ls->L,
"attempt to assign to const variable '%s'", getstr(varname));
luaK_semerror(ls, msg); /* error */
}
if (varname)
luaK_semerror(ls, "attempt to assign to const variable '%s'",
getstr(varname));
}
@ -523,9 +521,9 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) {
TString *tsname = getlocalvardesc(ls->fs, gt->nactvar)->vd.name;
const char *varname = getstr(tsname);
const char *msg = "<goto %s> at line %d jumps into the scope of local '%s'";
msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line, varname);
luaK_semerror(ls, msg); /* raise the error */
luaK_semerror(ls,
"<goto %s> at line %d jumps into the scope of local '%s'",
getstr(gt->name), gt->line, varname); /* raise the error */
}
@ -677,11 +675,10 @@ static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {
** generates an error for an undefined 'goto'.
*/
static l_noret undefgoto (LexState *ls, Labeldesc *gt) {
const char *msg = "no visible label '%s' for <goto> at line %d";
msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
/* breaks are checked when created, cannot be undefined */
lua_assert(!eqstr(gt->name, luaS_newliteral(ls->L, "break")));
luaK_semerror(ls, msg);
luaK_semerror(ls, "no visible label '%s' for <goto> at line %d",
getstr(gt->name), gt->line);
}
@ -1479,11 +1476,9 @@ static void breakstat (LexState *ls, int line) {
*/
static void checkrepeated (LexState *ls, TString *name) {
Labeldesc *lb = findlabel(ls, name, ls->fs->firstlabel);
if (l_unlikely(lb != NULL)) { /* already defined? */
const char *msg = "label '%s' already defined on line %d";
msg = luaO_pushfstring(ls->L, msg, getstr(name), lb->line);
luaK_semerror(ls, msg); /* error */
}
if (l_unlikely(lb != NULL)) /* already defined? */
luaK_semerror(ls, "label '%s' already defined on line %d",
getstr(name), lb->line); /* error */
}
@ -1718,8 +1713,7 @@ static lu_byte getlocalattribute (LexState *ls) {
else if (strcmp(attr, "close") == 0)
return RDKTOCLOSE; /* to-be-closed variable */
else
luaK_semerror(ls,
luaO_pushfstring(ls->L, "unknown attribute '%s'", attr));
luaK_semerror(ls, "unknown attribute '%s'", attr);
}
return VDKREG; /* regular variable */
}