lua-users home
lua-l archive

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

On Mon, Apr 2, 2012 at 10:08 PM, Sam Roberts <> wrote:
> On Mon, Apr 2, 2012 at 7:38 AM, Robert Klemme
> <> wrote:
>> On Mon, Apr 2, 2012 at 2:33 PM, Jerome Vuarand <> wrote:
>>> 2012/4/2 Robert Klemme <>:
>>>> Why is that?  What did I overlook?
>>> Every time you write the keyword "local", you create/declare a new
>>> local variable, which can shadow another one with the same name.
>> Ah!  I wasn't aware of that.  Page
>> does not mention this.
> The examples on that page show shadowing of local variable names.

But only with nesting, i.e. not the shadowing on the same level.

> Also: "The scope begins after the declaration and goes until the end
> of the block."

Hmm...  But the statement is prefixed with "As such, you can write
local declarations anywhere you can write a statement." so it seems
the main point of the paragraph is the "anywhere" bit.  And I cannot
find any mention that multiple local variables with the same
identifier inside a scope are legal in Lua - which is not too common
among programming languages.  I agree, the fact can be deduced from
the page - but it could be worded much clearer.

Kind regards


remember.guy do |as, often| as.you_can - without end