[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: 5.2: equality for closures
- From: Gé Weijers <ge@...>
- Date: Wed, 29 Jun 2011 04:15:23 -0700 (PDT)
On Wed, 29 Jun 2011, Alexander Gladysh wrote:
In our code we heavily use this function:
local unique_object = function()
-- Note that table is not acceptable, since its contents are not constant.
return function() end
It returns globally unique constant object that then (usually) is used
as a table key (usually to avoid name clashes).
You could use:
local function unique_object()
local v = 0
return function () v = v + 1; return v end
Each closure returned has a reference to a different 'v', and that is
'discernable' if you call the function, so each call to unique_object
returns a different closure.