lua-users home
lua-l archive

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


2012/11/21 Kevin Martin <kev82@khn.org.uk>:


> I'm sorry if it wasn't clear. The keyword as I intended it would not solve David Favro's problem, as in this example:
>
>> local rv1;
>> repeat
>>    relocal rv1, rv2 = foo();
>>    until rv2;
>> -- use rv1 here…
>
> rv1 is an upvalue from the point of view of the relocal statement, hence a new rv1 would be declared shadowing the correct rv1.
>

In that case I still don't understand "relocal".  In fact,
that is what "local" does: shadow the original rv1,
where "shadow" means "temporarily make invisible".

When I persuaded myself that I understood "relocal",
I though it meant "create a new local variable only if
no local variable by that name is visible, otherwise
use the one that is visible".  Basically, syntactic
sugar to save you declaring the new loval variables
when they are not all new.

BTW the old rv1 is only an upvalue when the new rv1 is
inside a function.  In the code you give, everything inside
the repeat is still at the same call stack level, so the old
rv1 is still just a local variable.