lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On 2019-08-08 6:06 p.m., Soni "They/Them" L. wrote:


On 2019-08-07 8:28 p.m., Egor Skriptunoff wrote:
t = {}
for j = 1, 2 do
   t[j] = function(x) return 2*x end
end
print(t[1] == t[2])

Lua 5.1    false
Lua 5.2    true
Lua 5.3    true
Lua 5.4    false

It seems that the equality between function values has returned back to its Lua 5.1 semantics.

1)
Why "function values caching" has been removed from Lua 5.4?

2)
Could we rely on the fact that in Lua 5.4+ any created function is unique value?

Lua 5.4 has const locals in loops. Each loop iteration gets a new j, which is const.

That just means each closure is using a different upvalue, and gets closed on each loop iteration. Try calling them!

(Well, I could be wrong, I guess. Correct me if I'm wrong.)

Nvm the previous message, I misread the OP.