int id = hw_RegisterEventHandlerEx(STRPTR name, int type, APTR data);
InstallEventHandler()
. Whenever you want this
event handler to trigger, you have to post an event to Hollywood's event
queue using the hw_PostEvent() or hw_PostEventEx()
function.
You have to specify a name for the new event type. This name must follow the
conventions for Hollywood variables because the user will need to use this
name when installing a handler for this event type using Hollywood's InstallEventHandler()
function. Thus, the name you specify here must not clash with any existing
event handler names and it must not use any spaces or special characters.
It has to start with a letter from the English alphabet.
In parameter 2, you need to pass the type of the event you would like to register. The following event types are currently recognized:
HWEVTHANDLER_STANDARD:
data
parameter must be set to a pointer to a
struct hwStandardEventHandler
which looks like this:
struct hwStandardEventHandler { void (*EvtFunc)(lua_State *L, int type, APTR userdata); }; |
The following items are members of this structure:
EvtFunc:
InstallEventHandler()
. The function you specify here may then push
additional values on the stack. When evtfunc
is called, Hollywood will have already
pushed a table to the stack and it will have set the Action
field of that table to
the name of your event for consistency with inbuilt Hollywood events. All other
values that your event handler may want to provide to the user's event callback
should also be stored in that table. Note that you must write this function even if
you do not want to push any additional values on the stack. EvtFunc
must not be
NULL
. The user data that is passed to EvtFunc
as the third parameter is the same
pointer that you provided in the call to hw_PostEvent()
or hw_PostEventEx().
HWEVTHANDLER_STANDARD
is identical to the event handler registered by
hw_RegisterEventHandler() so you might
also use the latter to register standard events.
HWEVTHANDLER_CUSTOM:
data
parameter must be set to a pointer to a struct hwCustomEventHandler
which looks like this:
struct hwCustomEventHandler { int (*PushData)(lua_State *L, int type, APTR udata); void (*PostCall)(lua_State *L, int type, APTR udata); void (*FreeEvent)(lua_State *L, int type, APTR udata); }; |
The following items are members of this structure:
PushData:
InstallEventHandler()
. The function you specify here may then push
additional values on the stack. Note that in comparison to events of type HWEVTHANDLER_STANDARD
,
Hollywood won't push any values on the stack for custom events. There will also
be no table on the stack as it is the case with HWEVTHANDLER_STANDARD
. Instead, your
plugin is given complete control over what the stack should look like when
Hollywood runs the user callback. For consistency reasons, however, it is
advised that you push a table, set the Action
field to the name of your
event and then store all additional values inside that table. You should
only deviate from this standard if you have very good reason to do so.
PostCall:
FreeEvent:
Note that you must provide functions for all of the structure members above,
even if they don't do anything. No structure member must be NULL
. The user data
that is passed to all the functions above as the third parameter is the same
pointer that you provided in the call to hw_PostEvent()
or hw_PostEventEx() when you posted the event.