mirror of
https://github.com/lua/lua.git
synced 2026-06-07 23:53:48 +00:00
New compile option LUA_COMPAT_LOOPVAR
When on, this option makes for-loop control variables not read only.
This commit is contained in:
13
lparser.c
13
lparser.c
@@ -1682,13 +1682,22 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isgen) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Control whether for-loop control variables are read-only
|
||||
*/
|
||||
#if defined(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, RDKCONST); /* control variable */
|
||||
new_varkind(ls, varname, LOOPVARKIND); /* control variable */
|
||||
checknext(ls, '=');
|
||||
exp1(ls); /* initial value */
|
||||
checknext(ls, ',');
|
||||
@@ -1715,7 +1724,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, RDKCONST); /* control variable */
|
||||
new_varkind(ls, indexname, LOOPVARKIND); /* control variable */
|
||||
/* other declared variables */
|
||||
while (testnext(ls, ',')) {
|
||||
new_localvar(ls, str_checkname(ls));
|
||||
|
||||
@@ -342,6 +342,13 @@
|
||||
#define LUA_COMPAT_GLOBAL
|
||||
|
||||
|
||||
/*
|
||||
@@ LUA_COMPAT_LOOPVAR makes for-loop control variables not read-only,
|
||||
** as they were in previous versions.
|
||||
*/
|
||||
/* #define LUA_COMPAT_LOOPVAR */
|
||||
|
||||
|
||||
/*
|
||||
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
|
||||
** functions in the mathematical library.
|
||||
|
||||
Reference in New Issue
Block a user