Event Module
Dependencies |
Globals
event
The Event API provides classes, functions and variables for interacting with the component network.
event.filter (params: { event?: string|string[], sender?: Object|Object[], values?: table<string,any> }) → EventFilter
Creates an Event filter expression.
event.ignore (…: Object)
Removes the running lua context from the listen queue of the given components. Basically the opposite of listen.
Details
| Name | Type | Description |
|---|---|---|
Objects |
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
| Name | Type | Description |
|---|---|---|
Objects |
A list of objects the computer should start listening to |
event.listening () → Object[]
Returns all signal senders this computer is listening to.
Details
| Name | Type | Description |
|---|---|---|
Objects |
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
| Name | Type | Description |
|---|---|---|
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 |
| Name | Type | Description |
|---|---|---|
Event |
string? |
The name of the returned signal. Nil when timeout got reached |
Sender |
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
| Name | Type | Description |
|---|---|---|
Filter |
EventFilter|{event?:string|string[],sender?:Object|Object[],values?:table<string,any>} |
Event filter |
Callback |
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
| Name | Type | Description |
|---|---|---|
Filter |
EventFilter|{event?:string|string[],sender?:Object|Object[],values?:table<string,any>} |
Event filter |
| Name | Type | Description |
|---|---|---|
Event |
string? |
The name of the returned signal |
Sender |
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
| Name | Type | Description |
|---|---|---|
Filter |
EventFilter|{event?:string|string[],sender?:Object|Object[],values?:table<string,any>} |
Event filter |
| Name | Type | Description |
|---|---|---|
Queue |
Event queue |
eventTask : Future
A future that is used as task to handle Events.
Types
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
| Name | Type | Description |
|---|---|---|
self |
||
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 |
| Name | Type | Description |
|---|---|---|
Event |
string? |
The name of the returned signal. Nil when timeout got reached |
Sender |
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
| Name | Type | Description |
|---|---|---|
self |
||
Filter |
EventFilter|{event?:string|string[],sender?:Object|Object[],values?:table<string,any>} |
Event filter |
| Name | Type | Description |
|---|---|---|
Event |
string? |
The name of the returned signal |
Sender |
The component representation of the signal sender |
|
Parameters |
any |
The parameters passed to the signal |