This removes the support for passing values to eventable.functions() and
eventable.object() which are bound to be passed to handlers. On top of
simplifying the code overall, this also avoids having three different
implementations of the fire() function.
In the existing code, the only case in which a handler argument is fixed
is for objects which pass themselves. This use case is covered by
eventable.object(), so the removed code was not realy ever used.
* Support debug-logging to stderr by defining the MATRIX_EVENTABLE_DEBUG_LOG
environment variable.
* Support for unhooking handlers from events.
* Simplify the low-level interface: eventable.functions() now returns the
created functions directly, cutting down on an intermediate table.
* A new eventable.object() allows adding :hook(), :unhook() and :fire()
methods to any table. Firing events always sends the table itself as first
event parameter when firing any event.
The matrix.eventable module/function returns a table with a pair of functions
which can be used to connect event handlers to events, and to generate them.
Basic usage is as follows:
obj = eventable()
obj.hook("event-name", print) -- Handle the event with "print"
obj.fire("event-name", "Hello, world") -- Prints "Hello, world"
This initial implementation has the following limitations:
* Event handlers are always invoked in the same order in which they have been
connected using the .hook() function.
* Individual event handlers cannot be disconnected. Only disconnecting all
handlers for en event at once is possible via .hook("event", nil).