[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question about local functions inside functions.
- From: Tom N Harris <telliamed@...>
- Date: Mon, 18 Apr 2016 11:39:30 -0400
On 4/18/2016 10:11 AM, Ulrich Schmidt wrote:
I know. The background of my question was: I like to hide functions inside functions hided inside functions.
This helps me to make excessive use of code folding in ZBS and keeps things as local as possible.
That's what do-end blocks are for.
But i was not sure, it slows down something.
Starting in Lua 5.2, a closure that does not have any upvalues will be
cached and reused.
function noclosure(x)
a = x
return function()
return a
end
end
function withclosure(x)
local a = x
return function()
return a
end
end
print(noclosure(1) == noclosure(2))
-- true
print(withclosure(1) == withclosure(2))
-- false
-- tom
<telliamed@whoopdedo.org>