Removed compiler option LUA_COMPAT_LOOPVAR

It makes loop variables read-only, but it does not restore the old
semantics, so it is not helpful for compatibility.
This commit is contained in:
Roberto I
2026-07-13 15:18:37 -03:00
parent b996f8fd1b
commit 6ca33260d2
3 changed files with 2 additions and 23 deletions

View File

@@ -1685,22 +1685,13 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isgen) {
}
/*
** Control whether for-loop control variables are read-only
*/
#if LUA_COMPAT_LOOPVAR
#define LOOPVARKIND VDKREG
#else /* by default, these variables are read only */
#define LOOPVARKIND RDKCONST
#endif
static void fornum (LexState *ls, TString *varname, int line) {
/* fornum -> NAME = exp,exp[,exp] forbody */
FuncState *fs = ls->fs;
int base = fs->freereg;
new_localvarliteral(ls, "(for state)");
new_localvarliteral(ls, "(for state)");
new_varkind(ls, varname, LOOPVARKIND); /* control variable */
new_varkind(ls, varname, RDKCONST); /* control variable */
checknext(ls, '=');
exp1(ls); /* initial value */
checknext(ls, ',');
@@ -1727,7 +1718,7 @@ static void forlist (LexState *ls, TString *indexname) {
new_localvarliteral(ls, "(for state)"); /* iterator function */
new_localvarliteral(ls, "(for state)"); /* state */
new_localvarliteral(ls, "(for state)"); /* closing var. (after swap) */
new_varkind(ls, indexname, LOOPVARKIND); /* control variable */
new_varkind(ls, indexname, RDKCONST); /* control variable */
/* other declared variables */
while (testnext(ls, ',')) {
new_localvar(ls, str_checkname(ls));

View File

@@ -348,15 +348,6 @@
#endif
/*
@@ LUA_COMPAT_LOOPVAR makes for-loop control variables not read-only,
** as they were in previous versions.
*/
#if !defined(LUA_COMPAT_LOOPVAR)
#define LUA_COMPAT_LOOPVAR 0
#endif
/*
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
** functions in the mathematical library.

View File

@@ -9623,9 +9623,6 @@ makes @id{global} a regular word.
The control variable in @Rw{for} loops is read only.
If you need to change it,
declare a local variable with the same name in the loop body.
The compilation option @id{LUA_COMPAT_LOOPVAR} (see @id{luaconf.h})
makes these variables regular (writable).
}
@item{