[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Tracking number of pairs in a dictionary
- From: Petite Abeille <petite.abeille@...>
- Date: Thu, 1 Oct 2009 20:19:05 +0200
On Oct 1, 2009, at 8:06 PM, Jorge wrote:
So, THAT is what closures are for! :)
Among other things, e.g.:
local function counter()
local aCount = 0
return function()
aCount = aCount + 1
return aCount
end
end
local aCounter = counter()
local anotherCounter = counter()
print( 'aCounter', aCounter() )
print( 'aCounter', aCounter() )
print( 'anotherCounter', anotherCounter() )
> aCounter 1
> aCounter 2
> anotherCounter 1