lua-users home
lua-l archive

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


On 4 September 2012 22:37, James Norton <jamesnorton@gmail.com> wrote:
> I want to be able to remove the listener using the same
> syntax:
>
> someObject:removeEventListener("myEvent", myListener)
>
> The problem with this is that I can't think of a way to associate the
> function on the stack at this point (myListener), with the reference I
> stored earlier.

Just two quick ideas:

1) since luaL_ref just returns a unique integer key in the registry
(which is just a Lua table) and stores the value in it, you can
traverse the registry and search for the given value
2) create a separate (weak) Lua table and use it to map the values to
keys returned by luaL_ref

1) requires CPU, 2) requires memory, choose what you prefer :)