[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question about use of local and Lua 5.2 optimization
- From: Francisco Olarte <folarte@...>
- Date: Thu, 1 Jun 2017 17:33:43 +0200
On Thu, Jun 1, 2017 at 11:24 PM, Martin <eden_martin_fuhrspam@gmx.de> wrote:
> On 05/31/2017 06:11 PM, Andrew Starks wrote:
...
>> An upvalue is a local that has been declared in a parent scope and not
>> covered over by a local declaration:
> Function parameters are upvalues too. This looked quite strange to me.
> local f =
> function(a)
> return
> function()
> a = a + 1
> return a
> end
> end
> local counter = f(0)
> print(counter(), counter())
Doesn't look weird to me. a is local to f, the outer function, (
parameters act like automagically initialized locals in many languages
) , so it is an unconvered local in the parent scope ( which is the
outer function body ) of the inner function.
Francisco Olarte.