dcsext.interfaces.EventHandler
EventHandler class.
Contents
Description
Provides a common way for objects to process events. Classes inheriting EventHandler map DCS event ids to handler methods which onEvent dispatches protected from errors.
Metamethods
eventhandler:__init()
Class constructor. Initializes the internal event handler table. Subclasses must call this from their own constructors, optionally after assigning self._logger to reuse a specific logger instance.
Methods
eventhandler:_overridehandlers(handlers)
[internal] Overrides event handlers in the object. Used mainly internally in inheriting constructor functions.
Parameters
- handlers
- map of DCS event id to handler function merged into the handlers already registered on this object
eventhandler:register()
Register this class with the DCS event handler system. Requires the DCS world global, only available inside the mission scripting environment. Events are delivered to onEvent until unregister is called.
eventhandler:unregister()
Remove this class from the DCS event handler system. No further events are delivered to onEvent afterwards.
eventhandler:onEvent(event)
Process a DCS event. Looks up the handler registered for event.id and invokes it with the event object. Implementers provide handlers through _overridehandlers keyed by world.event ids. Handler errors are caught and routed to the dcsext error handler so they never propagate into the DCS event loop.
Parameters
- event
- the event object to dispatch