Hi Lua Team,
In the part of the manual related to
changes (
https://www.lua.org/manual/5.5/readme.html#changes ),
it says:
> for-loop variables are read only
I performed a few tests on that
matter with Lua 5.5 on
Linux + Windows, and I have a doubt.
1. Executing the following statement:
lua -e "for i, v in ipairs({1}) do i = 3 end"
it throws the error
`lua: (command line):1: attempt to assign to const variable 'i'`
2. Executing this statement:
lua -e "for i, v in ipairs({1}) do v = 3 end"
it does not throw any error.
Then I thought: hmm, probably
it assigns the value back.
However, the next test shows
it does not.
3. Executing this statement:
lua -e "local t = {1}; for i, v in ipairs(t) do v = 3 end; print(t[1]);"
prints 1, showing that the
t[1] value didn't change.
So, my question is: according to
the manual
> for-loop variables are read only
the second part above (2.) shouldn't throw?