|
@@ -416,6 +416,17 @@ static void markupval (FuncState *fs, int level) {
|
|
|
}
|
|
|
|
|
|
|
|
|
+/*
|
|
|
+** Mark that current block has a to-be-closed variable.
|
|
|
+*/
|
|
|
+static void marktobeclosed (FuncState *fs) {
|
|
|
+ BlockCnt *bl = fs->bl;
|
|
|
+ bl->upval = 1;
|
|
|
+ bl->insidetbc = 1;
|
|
|
+ fs->needclose = 1;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/*
|
|
|
** Find a variable with the given name 'n'. If it is an upvalue, add
|
|
|
** this upvalue into all intermediate functions. If it is a global, set
|
|
@@ -1599,7 +1610,7 @@ static void forlist (LexState *ls, TString *indexname) {
|
|
|
line = ls->linenumber;
|
|
|
adjust_assign(ls, 4, explist(ls, &e), &e);
|
|
|
adjustlocalvars(ls, 4); /* control variables */
|
|
|
- markupval(fs, fs->nactvar); /* last control var. must be closed */
|
|
|
+ marktobeclosed(fs); /* last control var. must be closed */
|
|
|
luaK_checkstack(fs, 3); /* extra space to call generator */
|
|
|
forbody(ls, base, line, nvars - 4, 1);
|
|
|
}
|
|
@@ -1703,11 +1714,9 @@ static int getlocalattribute (LexState *ls) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-static void checktoclose (LexState *ls, int level) {
|
|
|
+static void checktoclose (FuncState *fs, int level) {
|
|
|
if (level != -1) { /* is there a to-be-closed variable? */
|
|
|
- FuncState *fs = ls->fs;
|
|
|
- markupval(fs, level + 1);
|
|
|
- fs->bl->insidetbc = 1; /* in the scope of a to-be-closed variable */
|
|
|
+ marktobeclosed(fs);
|
|
|
luaK_codeABC(fs, OP_TBC, reglevel(fs, level), 0, 0);
|
|
|
}
|
|
|
}
|
|
@@ -1751,7 +1760,7 @@ static void localstat (LexState *ls) {
|
|
|
adjust_assign(ls, nvars, nexps, &e);
|
|
|
adjustlocalvars(ls, nvars);
|
|
|
}
|
|
|
- checktoclose(ls, toclose);
|
|
|
+ checktoclose(fs, toclose);
|
|
|
}
|
|
|
|
|
|
|