aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2026-07-13 15:18:37 -0300
committerRoberto I <roberto@inf.puc-rio.br>2026-07-13 15:18:37 -0300
commit6ca33260d26f1b8fab982b13c89de1f445361328 (patch)
tree8c482c024f28adb451f18a65d851ab96361f78e5
parentb996f8fd1be7fb711cc6f754a31a1c87d2c2fd9b (diff)
downloadlua-6ca33260d26f1b8fab982b13c89de1f445361328.tar.gz
lua-6ca33260d26f1b8fab982b13c89de1f445361328.tar.bz2
lua-6ca33260d26f1b8fab982b13c89de1f445361328.zip
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.
-rw-r--r--lparser.c13
-rw-r--r--luaconf.h9
-rw-r--r--manual/manual.of3
3 files changed, 2 insertions, 23 deletions
diff --git a/lparser.c b/lparser.c
index af2b64d1..fe29194c 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1685,22 +1685,13 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isgen) {
1685} 1685}
1686 1686
1687 1687
1688/*
1689** Control whether for-loop control variables are read-only
1690*/
1691#if LUA_COMPAT_LOOPVAR
1692#define LOOPVARKIND VDKREG
1693#else /* by default, these variables are read only */
1694#define LOOPVARKIND RDKCONST
1695#endif
1696
1697static void fornum (LexState *ls, TString *varname, int line) { 1688static void fornum (LexState *ls, TString *varname, int line) {
1698 /* fornum -> NAME = exp,exp[,exp] forbody */ 1689 /* fornum -> NAME = exp,exp[,exp] forbody */
1699 FuncState *fs = ls->fs; 1690 FuncState *fs = ls->fs;
1700 int base = fs->freereg; 1691 int base = fs->freereg;
1701 new_localvarliteral(ls, "(for state)"); 1692 new_localvarliteral(ls, "(for state)");
1702 new_localvarliteral(ls, "(for state)"); 1693 new_localvarliteral(ls, "(for state)");
1703 new_varkind(ls, varname, LOOPVARKIND); /* control variable */ 1694 new_varkind(ls, varname, RDKCONST); /* control variable */
1704 checknext(ls, '='); 1695 checknext(ls, '=');
1705 exp1(ls); /* initial value */ 1696 exp1(ls); /* initial value */
1706 checknext(ls, ','); 1697 checknext(ls, ',');
@@ -1727,7 +1718,7 @@ static void forlist (LexState *ls, TString *indexname) {
1727 new_localvarliteral(ls, "(for state)"); /* iterator function */ 1718 new_localvarliteral(ls, "(for state)"); /* iterator function */
1728 new_localvarliteral(ls, "(for state)"); /* state */ 1719 new_localvarliteral(ls, "(for state)"); /* state */
1729 new_localvarliteral(ls, "(for state)"); /* closing var. (after swap) */ 1720 new_localvarliteral(ls, "(for state)"); /* closing var. (after swap) */
1730 new_varkind(ls, indexname, LOOPVARKIND); /* control variable */ 1721 new_varkind(ls, indexname, RDKCONST); /* control variable */
1731 /* other declared variables */ 1722 /* other declared variables */
1732 while (testnext(ls, ',')) { 1723 while (testnext(ls, ',')) {
1733 new_localvar(ls, str_checkname(ls)); 1724 new_localvar(ls, str_checkname(ls));
diff --git a/luaconf.h b/luaconf.h
index 0a71370f..042932e1 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -349,15 +349,6 @@
349 349
350 350
351/* 351/*
352@@ LUA_COMPAT_LOOPVAR makes for-loop control variables not read-only,
353** as they were in previous versions.
354*/
355#if !defined(LUA_COMPAT_LOOPVAR)
356#define LUA_COMPAT_LOOPVAR 0
357#endif
358
359
360/*
361@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated 352@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
362** functions in the mathematical library. 353** functions in the mathematical library.
363** (These functions were already officially removed in 5.3; 354** (These functions were already officially removed in 5.3;
diff --git a/manual/manual.of b/manual/manual.of
index 5e113336..65261695 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -9623,9 +9623,6 @@ makes @id{global} a regular word.
9623The control variable in @Rw{for} loops is read only. 9623The control variable in @Rw{for} loops is read only.
9624If you need to change it, 9624If you need to change it,
9625declare a local variable with the same name in the loop body. 9625declare a local variable with the same name in the loop body.
9626
9627The compilation option @id{LUA_COMPAT_LOOPVAR} (see @id{luaconf.h})
9628makes these variables regular (writable).
9629} 9626}
9630 9627
9631@item{ 9628@item{