aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lparser.c13
-rw-r--r--luaconf.h7
2 files changed, 18 insertions, 2 deletions
diff --git a/lparser.c b/lparser.c
index b3855d4c..b27463af 100644
--- a/lparser.c
+++ b/lparser.c
@@ -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
1685static void fornum (LexState *ls, TString *varname, int line) { 1694static 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));
diff --git a/luaconf.h b/luaconf.h
index 96a77802..f076c984 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -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;