Thread: I admit defeat
View Single Post
12-06-13, 09:56 PM   #5
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
What p3lim does is create his own implementation of RegisterEvent, where he can pass a handler function as a second argument to it. The code then checks whether a handler is already present for the passed event. If not, it creates a table entry with the event as the key and the handler as the value (the value is of type function). If there is already a handler, and the handler is a function, it changes the table entry so that the key is the event and the value is a new table containing the old and the new handler (so it is an array with 2 values, both are of type function) and sets his metatable to it (more on that below). If the handler is not of type function (it will then be a type table) it just injects the new handler into that table.

The __call metamethod allows a table to be called like a function and defines what the return of that should be. The first argument it gets is the table itself, followed by all the arguments passed in table call. In p3lim's case it tells it to execute all the handlers registered to the given event.
  Reply With Quote