[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: local scope once again
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Tue, 12 Dec 2006 11:33:35 -0500
Leo Razoumov wrote:
> I am surprised to see that there are three different local 'x'
> variables. All of them belong to the same "block" which is foo()
> function body and, thus, should have the same scope. Why does not Lua
> collapses them into just one local x variable??
It's a feature of lua that the local keyword create a *new* local
variable, unconditionally. The end keyword closes a lexical scope, but
the beginning of the scope is not defined by the beginning of the block
but instead by the variable creation, which can happen after the
beginning of the block as in your examples (to be precise, the scope
starts just after variable initialisation, so a statement like "local
data = data.subdata" makes sense).