|
> 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
Yes. No. Yes (although it looks like a bad practice to declare
several variables with the same name in the same scope).
-- Roberto