>Lua doesn’t need a special case here, since it uses an iterator protocol that produces values rather than mutating a visible state variable, so there’s no problem with having the loop variable be truly distinct on each run through the loop.
Lua works the same way, every iteration has different ‘i’ in iterative version of for loop:
local fs = { }
for i = 1, 5 do
table.insert(fs,
function () print(i) end)
end
for i,f in ipairs(fs) do
f()
end
-- 1 2 3 4 5
What Lua lacks is a will of its authors to add real-life features like (de)structuring, __[gs]et, multi-spread, quick lambda syntax, generic classlib, generic byte buffers, etc. Read FRs in mailing list before any release for details. It is a DIY in C kit, but how long do you DIY until it’s annoying?As a long-time Lua 5.1/2 user who likes it, I must admit that with all js quirks and lacks js is simply more practical and that’s what matters.