Re: Lua 5.5: LUA_COMPAT_LOOPVAR does not fully restore the previous behavior
Roberto Ierusalimschy <[email protected]> Fri, 29 May 2026 16:38:43 -0300
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
> I would like to report what I believe is an oversight (or at least an > under-documented limitation) in the new LUA_COMPAT_LOOPVAR option in > Lua 5.5. > > The comment in luaconf.h states: > > @@ LUA_COMPAT_LOOPVAR makes for-loop control variables not read-only, > ** as they were in previous versions. > > The phrase "as they were in previous versions" suggests that enabling > this option is supposed to restore the Lua 5.4 behavior. In practice, > the option only flips the variable kind from RDKCONST to VDKREG (see > lparser.c, around the LOOPVARKIND macro). The compiler stops rejecting > the assignment, but the underlying single-slot design of 5.5 is > unchanged: the user-visible loop variable and the internal control > variable share the same stack register (e.g. ra+3 for a generic for). > As a consequence, any assignment to the loop variable inside the body > corrupts the value that OP_TFORCALL passes back to the iterator on the > next iteration. You are right. Thanks for the feedback. -- Roberto -- You received this message because you are subscribed to the Google Groups "lua-l" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/lua-l/20260529193843.GA122789%40arraial.inf.puc-rio.br.