Event Module

Globals

event

The Event API provides classes, functions and variables for interacting with the component network.

event.clear ()

Clears every signal from the signal queue.

event.filter (params: { event?: string|string[], sender?: Object|Object[], values?: table<string,any> }) → EventFilter

Creates an Event filter expression.

Details
Parameters
Name Type Description

Params params

{ event?: string|string[], sender?: Object|Object[], values?: table<string,any> }

Filter parameters

Return Values
Name Type Description

Filter filter

EventFilter

Event filter

event.ignore (…​: Object)

Removes the running lua context from the listen queue of the given components. Basically the opposite of listen.

Details
Parameters
Name Type Description

Objects …​

Object

A list of objects this computer should stop listening to

event.ignoreAll ()

Stops listening to any signal sender. If afterwards there are still coming signals in, it might be the system itself or caching bug.

event.listen (…​: Object)

Adds the running lua context to the listen queue of the given components.

Details
Parameters
Name Type Description

Objects …​

Object

A list of objects the computer should start listening to

event.listening () → Object[]

Returns all signal senders this computer is listening to.

Details
Return Values
Name Type Description

Objects listening

Object[]

An array containing all objects this computer is currently listening to

event.pull (timeout: number?) → (string?, Object, …​)

Waits for a signal in the queue. Blocks the execution until a signal got pushed to the signal queue, or the timeout is reached.
Returns directly if there is already a signal in the queue (the tick doesn¬タルt get yielded).

Details
Parameters
Name Type Description

Timeout timeout

number

The amount of time needs to pass until pull unblocks when no signal got pushed. If not set, the function will block indefinitely until a signal gets pushed. If set to 0 (int), will not yield the tick and directly return with the signal data or nil if no signal was in the queue

Return Values
Name Type Description

Event event

string?

The name of the returned signal. Nil when timeout got reached

Sender sender

Object

The component representation of the signal sender. Not set when timeout got reached

Parameters …​

any

The parameters passed to the signal. Not set when timeout got reached

event.registerListener (filter: EventFilter, cb: fun(event, sender, …​)) → integer

Registers the given function as a listener. When event.pull() pulls a signal from the queue, that matches the given Event-Filter, a Task will be created using the function and the signals parameters will be passed into the function.

Details
Parameters
Name Type Description

Filter filter

EventFilter|{event?:string|string[],sender?:Object|Object[],values?:table<string,any>}

Event filter

Callback cb

fun(event, sender, …​)

Callback that will be called on every event that matches the filter

event.waitFor (filter: EventFilter) → Future

Returns a Future that resolves when a signal got polled that matches the given Event Filter.

Details
Parameters
Name Type Description

Filter filter

EventFilter|{event?:string|string[],sender?:Object|Object[],values?:table<string,any>}

Event filter

Return Values
Name Type Description

Event event

string?

The name of the returned signal

Sender sender

Object

The component representation of the signal sender

Parameters …​

any

The parameters passed to the signal

event.queue (filter: EventFilter) → EventQueue

Creates a new event queue. When this variable closes or gets garbage collected, it will stop receiving signals.

Details
Parameters
Name Type Description

Filter filter

EventFilter|{event?:string|string[],sender?:Object|Object[],values?:table<string,any>}

Event filter

Return Values
Name Type Description

Queue queue

EventQueue

Event queue

eventTask : Future

A future that is used as task to handle Events.

Types

EventQueue

EventQueue.pull (timeout: number?) → (string?, Object, …​)

Waits for a signal in the queue. Blocks the execution until a signal got pushed to the signal queue, or the timeout is reached. Returns directly if there is already a signal in the queue (the tick doesn¬タルt get yielded).

Details
Parameters
Name Type Description

self self

EventQueue

Timeout timeout

number

The amount of time needs to pass until pull unblocks when no signal got pushed. If not set, the function will block indefinitely until a signal gets pushed. If set to 0 (int), will not yield the tick and directly return with the signal data or nil if no signal was in the queue

Return Values
Name Type Description

Event event

string?

The name of the returned signal. Nil when timeout got reached

Sender sender

Object

The component representation of the signal sender. Not set when timeout got reached

Parameters …​

any

The parameters passed to the signal. Not set when timeout got reached

EventQueue.waitFor (filter: EventFilter) → (string?, Object, …​)

Returns a Future that resolves when a signal got added to the queue that matches the given Event Filter.

Details
Parameters
Name Type Description

self self

EventQueue

Filter filter

EventFilter|{event?:string|string[],sender?:Object|Object[],values?:table<string,any>}

Event filter

Return Values
Name Type Description

Event event

string?

The name of the returned signal

Sender sender

Object

The component representation of the signal sender

Parameters …​

any

The parameters passed to the signal