Class Sentry

Allows the table to contain events at which others can register their handlers.

The functionality is seamless, as in any key that starts with On ends up being interpreted as an event, for purposes of registering and for purposes of calling.

There is also a special handling to make setting of handlers easier -- it is only necessary to assign a function or a table of functions to the event key and they get automatically appended to the already existing event handler list.

Usage:

     local MyObject = Sentry:New()
    
     -- append a two custom event handlers to the OnAction name
     MyObject.OnAction = function(v)
       print("acted 1")
       return v
     end
     MyObject.OnAction = function(v)
       print("acted 2")
     end
    
     -- invoke the event handlers
     MyObject.OnAction:Invoke() -- invokes both
     MyObject.OnAction() -- invokes both, equivalent to using Invoke
    
     MyObject.OnAction(true)  -- invokes only the first one
     -- the execution of the second one is cancelled because the first one returned true
    
     MyObject.OnAction(false) -- invokes both and removes the first one from the list
     MyObject.OnAction() -- invokes only the second one as the first one was removed

Functions

Sentry:New (t, events) Creates new instance of Sentry.

Tables

Sentry Accessible fields.

Class EventHandler

EventHandler:Invoke (...) Invokes the execution of all registered functions, until one returns a non-false result.


Functions

Sentry:New (t, events)
Creates new instance of Sentry.

Remarks:

    The second return value, corresponding to the events parameter, should not be directly exposed to the user, as its functionality is already presented in the Sentry itself.

Parameters:

Returns:

  1. Sentry
  2. {[string]=EventHandler} events parameter or a newly created table altered in such a way, that any key starting with On creates a new EventHandler set

Tables

Sentry
Accessible fields.

Remarks:

    The EventHandlers do not need to be created, they are formed when accessed for the first time.

Fields:

  • On__name__ EventHandler, func or {func,...} list of event handlers when accessed, function or a list of functions that appends to the event handler list when assigned to

Class EventHandler

Represents a set of functions that handle an event.
EventHandler:Invoke (...)
Invokes the execution of all registered functions, until one returns a non-false result.

Remarks:

    The event handler can be called directly, instead of h:Invoke(...) you can use h(...)

Parameters:

  • ... any parameters that may be expected by the handlers themselves
generated by LDoc 1.4.3 Last updated 2017-06-01 23:07:48