lua-users home
lua-l archive

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


well, in your example, "local x" has been declared when running
finally-block. Declaration happens in parsing stage, and only effects
successding statements within the same code block; while assignment
happens when code's running.

In your case, it will throw an error such like "attempt to index a nil
value", or something else, because though "local x" is declared, it's
initial value is un-defined, and has not been assigned an empty table
yet.

On Feb 1, 2008 2:00 PM, Mark Hamburg <mhamburg@adobe.com> wrote:
> on 1/31/08 7:43 PM, Hu Qiwei at huqiwei@gmail.com wrote:
>
> > 3) Scoping change: local variables defined in try-block will live till
> > the end of finally- or catch- block. by popular demand.
>
> Isn't that tricky to make work with variables that may not even be declared
> at the point where one exits the try block?
>
>    try
>
>        if true then
>            return
>        end
>
>        local x = { }
>
>    finally
>
>        x[ 1 ] = "foo"
>
>    end
>
> "x" isn't even defined at the point where we exit the try block. (I had an
> even more twisted version where I used the ability to redeclare local
> variables and started the try block with "local x = 3".
>
> Mark
>
>
>