lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Valeriy E. Ushakov wrote:
> Can you break the dependency by making on_click pass the object to the
> handler?
> 
>   b:on_click(function(b) b:some_method() end)
> 

Yes, but it is only a partial solution. Consider a bit more complicated
example:

local a = Button()
local b = Button()

a:on_click(function() b:some_method() end)
b:on_click(function() a:some_method() end)

Now `a' holds a reference (via "refs" table) to the first anonymous
function, which in turn refers to `b', which holds a reference to the
second anonymous function, which finally refers to `a'. Here we get a
cycle of length 4 instead of 2.

-- Gregory Bonik