[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: Martin <eden_martin_fuhrspam@...>
- Date: Thu, 1 Jun 2017 14:24:51 -0700
On 05/31/2017 06:11 PM, Andrew Starks wrote:
> A closure is a function, plus its environment. This includes its
> upvalues and its global environment, which in Lua 5.2 is an upvalue
> called _ENV.
>
> An upvalue is a local that has been declared in a parent scope and not
> covered over by a local declaration:
>
> local o = function()
> local x = 1
> return function ()
> print (x)
> x = x + 1
> end
> end
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())
-- Martin