mirror of
https://github.com/lua/lua.git
synced 2025-07-24 12:42:36 +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:
parent
3dbb1a4b89
commit
50fd8d03c3
3 changed files with 21 additions and 20 deletions
9
lcode.c
9
lcode.c
|
@ -40,7 +40,14 @@ static int codesJ (FuncState *fs, OpCode o, int sj, int k);
|
||||||
|
|
||||||
|
|
||||||
/* semantic error */
|
/* 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 */
|
ls->t.token = 0; /* remove "near <token>" from final message */
|
||||||
luaX_syntaxerror(ls, msg);
|
luaX_syntaxerror(ls, msg);
|
||||||
}
|
}
|
||||||
|
|
2
lcode.h
2
lcode.h
|
@ -97,7 +97,7 @@ LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,
|
||||||
int ra, int asize, int hsize);
|
int ra, int asize, int hsize);
|
||||||
LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
|
LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
|
||||||
LUAI_FUNC void luaK_finish (FuncState *fs);
|
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
|
#endif
|
||||||
|
|
30
lparser.c
30
lparser.c
|
@ -306,11 +306,9 @@ static void check_readonly (LexState *ls, expdesc *e) {
|
||||||
default:
|
default:
|
||||||
return; /* other cases cannot be read-only */
|
return; /* other cases cannot be read-only */
|
||||||
}
|
}
|
||||||
if (varname) {
|
if (varname)
|
||||||
const char *msg = luaO_pushfstring(ls->L,
|
luaK_semerror(ls, "attempt to assign to const variable '%s'",
|
||||||
"attempt to assign to const variable '%s'", getstr(varname));
|
getstr(varname));
|
||||||
luaK_semerror(ls, msg); /* error */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -523,9 +521,9 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
|
||||||
static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) {
|
static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) {
|
||||||
TString *tsname = getlocalvardesc(ls->fs, gt->nactvar)->vd.name;
|
TString *tsname = getlocalvardesc(ls->fs, gt->nactvar)->vd.name;
|
||||||
const char *varname = getstr(tsname);
|
const char *varname = getstr(tsname);
|
||||||
const char *msg = "<goto %s> at line %d jumps into the scope of local '%s'";
|
luaK_semerror(ls,
|
||||||
msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line, varname);
|
"<goto %s> at line %d jumps into the scope of local '%s'",
|
||||||
luaK_semerror(ls, msg); /* raise the error */
|
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'.
|
** generates an error for an undefined 'goto'.
|
||||||
*/
|
*/
|
||||||
static l_noret undefgoto (LexState *ls, Labeldesc *gt) {
|
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 */
|
/* breaks are checked when created, cannot be undefined */
|
||||||
lua_assert(!eqstr(gt->name, luaS_newliteral(ls->L, "break")));
|
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) {
|
static void checkrepeated (LexState *ls, TString *name) {
|
||||||
Labeldesc *lb = findlabel(ls, name, ls->fs->firstlabel);
|
Labeldesc *lb = findlabel(ls, name, ls->fs->firstlabel);
|
||||||
if (l_unlikely(lb != NULL)) { /* already defined? */
|
if (l_unlikely(lb != NULL)) /* already defined? */
|
||||||
const char *msg = "label '%s' already defined on line %d";
|
luaK_semerror(ls, "label '%s' already defined on line %d",
|
||||||
msg = luaO_pushfstring(ls->L, msg, getstr(name), lb->line);
|
getstr(name), lb->line); /* error */
|
||||||
luaK_semerror(ls, msg); /* error */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1718,8 +1713,7 @@ static lu_byte getlocalattribute (LexState *ls) {
|
||||||
else if (strcmp(attr, "close") == 0)
|
else if (strcmp(attr, "close") == 0)
|
||||||
return RDKTOCLOSE; /* to-be-closed variable */
|
return RDKTOCLOSE; /* to-be-closed variable */
|
||||||
else
|
else
|
||||||
luaK_semerror(ls,
|
luaK_semerror(ls, "unknown attribute '%s'", attr);
|
||||||
luaO_pushfstring(ls->L, "unknown attribute '%s'", attr));
|
|
||||||
}
|
}
|
||||||
return VDKREG; /* regular variable */
|
return VDKREG; /* regular variable */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue