Hi there,
My understanding is that variables declared with <close> should also be <const>. I've come across a situation where I think Lua is behaving correctly, but just want to confirm:
----------------
function closable(n)
return setmetatable( {}, {
__close=function() print( 'inside __close:', n ) end
} )
end
function foo()
print( 'starting foo' )
local x<close> = closable(1)
local x<close> = closable(2)
local x<close> = closable(3)
print( 'ending foo' )
end
foo()
-------------------
The above outputs:
starting foo
ending foo
inside __close: 3
inside __close: 2
inside __close: 1
--------------------
The above runs without error even though there are redeclarations of `x<close>` all with the same name, and it closes each of the 3 variables separately. Am I correct that the redeclaration of `x` is just hiding the previous ones and not changing their values and so it is allowed? Or is this a bug that Lua doesn't give an error? Can I rely on this behavior in the future? Thanks
David