diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2026-01-16 16:38:44 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2026-01-16 16:38:44 -0300 |
| commit | f5d1e8639bf5df24c761602354218df21f796a30 (patch) | |
| tree | be98de76942a21046e735d2f84cd2748bf377356 | |
| parent | 2a7cf4f319fc276f4554a8f6364e6b1ba4eb2ded (diff) | |
| download | lua-f5d1e8639bf5df24c761602354218df21f796a30.tar.gz lua-f5d1e8639bf5df24c761602354218df21f796a30.tar.bz2 lua-f5d1e8639bf5df24c761602354218df21f796a30.zip | |
New compile option LUA_COMPAT_LOOPVAR
When on, this option makes for-loop control variables not read only.
| -rw-r--r-- | lparser.c | 13 | ||||
| -rw-r--r-- | luaconf.h | 7 |
2 files changed, 18 insertions, 2 deletions
| @@ -1682,13 +1682,22 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isgen) { | |||
| 1682 | } | 1682 | } |
| 1683 | 1683 | ||
| 1684 | 1684 | ||
| 1685 | /* | ||
| 1686 | ** Control whether for-loop control variables are read-only | ||
| 1687 | */ | ||
| 1688 | #if defined(LUA_COMPAT_LOOPVAR) | ||
| 1689 | #define LOOPVARKIND VDKREG | ||
| 1690 | #else /* by default, these variables are read only */ | ||
| 1691 | #define LOOPVARKIND RDKCONST | ||
| 1692 | #endif | ||
| 1693 | |||
| 1685 | static void fornum (LexState *ls, TString *varname, int line) { | 1694 | static void fornum (LexState *ls, TString *varname, int line) { |
| 1686 | /* fornum -> NAME = exp,exp[,exp] forbody */ | 1695 | /* fornum -> NAME = exp,exp[,exp] forbody */ |
| 1687 | FuncState *fs = ls->fs; | 1696 | FuncState *fs = ls->fs; |
| 1688 | int base = fs->freereg; | 1697 | int base = fs->freereg; |
| 1689 | new_localvarliteral(ls, "(for state)"); | 1698 | new_localvarliteral(ls, "(for state)"); |
| 1690 | new_localvarliteral(ls, "(for state)"); | 1699 | new_localvarliteral(ls, "(for state)"); |
| 1691 | new_varkind(ls, varname, RDKCONST); /* control variable */ | 1700 | new_varkind(ls, varname, LOOPVARKIND); /* control variable */ |
| 1692 | checknext(ls, '='); | 1701 | checknext(ls, '='); |
| 1693 | exp1(ls); /* initial value */ | 1702 | exp1(ls); /* initial value */ |
| 1694 | checknext(ls, ','); | 1703 | checknext(ls, ','); |
| @@ -1715,7 +1724,7 @@ static void forlist (LexState *ls, TString *indexname) { | |||
| 1715 | new_localvarliteral(ls, "(for state)"); /* iterator function */ | 1724 | new_localvarliteral(ls, "(for state)"); /* iterator function */ |
| 1716 | new_localvarliteral(ls, "(for state)"); /* state */ | 1725 | new_localvarliteral(ls, "(for state)"); /* state */ |
| 1717 | new_localvarliteral(ls, "(for state)"); /* closing var. (after swap) */ | 1726 | new_localvarliteral(ls, "(for state)"); /* closing var. (after swap) */ |
| 1718 | new_varkind(ls, indexname, RDKCONST); /* control variable */ | 1727 | new_varkind(ls, indexname, LOOPVARKIND); /* control variable */ |
| 1719 | /* other declared variables */ | 1728 | /* other declared variables */ |
| 1720 | while (testnext(ls, ',')) { | 1729 | while (testnext(ls, ',')) { |
| 1721 | new_localvar(ls, str_checkname(ls)); | 1730 | new_localvar(ls, str_checkname(ls)); |
| @@ -343,6 +343,13 @@ | |||
| 343 | 343 | ||
| 344 | 344 | ||
| 345 | /* | 345 | /* |
| 346 | @@ LUA_COMPAT_LOOPVAR makes for-loop control variables not read-only, | ||
| 347 | ** as they were in previous versions. | ||
| 348 | */ | ||
| 349 | /* #define LUA_COMPAT_LOOPVAR */ | ||
| 350 | |||
| 351 | |||
| 352 | /* | ||
| 346 | @@ LUA_COMPAT_MATHLIB controls the presence of several deprecated | 353 | @@ LUA_COMPAT_MATHLIB controls the presence of several deprecated |
| 347 | ** functions in the mathematical library. | 354 | ** functions in the mathematical library. |
| 348 | ** (These functions were already officially removed in 5.3; | 355 | ** (These functions were already officially removed in 5.3; |
