Canary client
2. What you expected to happen: Propertly working ‘for k, v in table do’ iteration without error
3. What actually happens: Error when
4. Category of bug: Lua interpreter? (client canary)
5. Reproducible steps:
Create resource.
Start create for k, v in table loop (without pairs or ipairs)
Error
attempt to call a table value (for iterator ‘for iterator’)
Previously this method works correctly without any errors, now big amount of my resources has this error
I’m not sure, but it can be only error on lua 5.4.
Unfortunately, that style of iteration (for k,v in table do end) is a custom Lua extension that I changed in a recent update. It was too error-prone and was bloating the TFORLOOP bits in the interpreter.
There are other features/changes planned for Lua where I did not want to include too many changes in the syntax. However, if the adoption rate of this feature is high I’ll be forced into reverting that commit.
so far players have been informed to switch to release, deleting this methodology is a bit of a shock to me because now I have to find all the resources that use this notation and there are definitely a ton of them. I don’t want to use pairs or ipairs because it’s not optimal and is relatively over 200% slower than for i = 1, #table do, so I have to apply this everywhere
The for i,player in GetActivePlayers() syntax was actually shorthand for pairs(). It placed next,table,nil onto the stack in a manner similar to pairs (for tables without a __pairs metamethod).
If you actually want to use array iteration you must be explicit:
local t = GetActivePlayers()
for i=1,#t do
...
end
Yes, I was just about to write that I could only use this for array. thank you for solving the thread and nice discussion. Then I have to start repairing tomorrow :(.
The feature was undocumented and hidden, likely came across by mistake as it is technically invalid Lua. It was also specific to Lua 5.4: a relatively undocumented runtime with a low adoption rate.
The feature was susceptible to errors and removing it simplifies future work elsewhere (maybe related to something you have complained about in another thread).