dreamworkAPI
Ctrl K
GitHub
classDocs / Event

Event

classsharedmenusource
Object → Event

A named list of handlers called one after another, a simpler Hook.

There are no stages and no return values: call runs every handler in priority order (lower first, equal priorities keep attach order) and returns nothing. Each handler runs in protected mode, a failing handler is reported and never stops the others.

Calls may nest, handlers attached during a call run from the next call on, handlers detached during a call are skipped right away.

Constructor

Event(name: string?): Event

Fields

NameTypeDescription
namestringThe name of the event.

Methods

attachAttaches a handler to the event.
awaitSuspends the caller until the event is next called, then returns its arguments.
callRuns every attached handler with ..., in priority order.
clearRemoves every handler attached to the event.
detachDetaches a handler previously passed to attach or once.
isRunningChecks if the event is running currently.
onceAttaches a one-shot handler, detached right before it runs.

#Event:attach

sharedmenusource
function Event:attach(handler: Event.Handler, priority: integer | nil)

Attaches a handler to the event.

If the handler is already attached, only its priority is updated (when a new one is supplied); it will not be attached twice.

Parameters
NameTypeDescription
handlerEvent.HandlerThe callback or callable object, receives the call arguments.
priorityinteger | nilThe priority of the handler; handlers with a lower value run earlier. Defaults to 0.

#Event:await

sharedmenuasyncsource
async function Event:await(): any

Suspends the caller until the event is next called, then returns its arguments.

Returns
TypeNameDescription
any...The arguments the event was called with.

#Event:call

sharedmenusource
function Event:call(...: any)

Runs every attached handler with ..., in priority order.

Each handler runs in protected mode: errors are reported and the rest still run. Non-function handlers are called through their __call metamethod with themselves first.

Parameters
NameTypeDescription
...anyArguments forwarded to every handler.

#Event:clear

sharedmenusource
function Event:clear()

Removes every handler attached to the event.

Handlers still pending in a running call are skipped.

#Event:detach

sharedmenusource
function Event:detach(handler: Event.Handler): boolean

Detaches a handler previously passed to attach or once.

Detaching during a call skips the handler in every call in progress.

Parameters
NameTypeDescription
handlerEvent.HandlerThe exact handler reference.
Returns
TypeNameDescription
booleanis_detachedReturns true if the handler was attached, otherwise false.

#Event:isRunning

sharedmenunodiscardsource
function Event:isRunning(): boolean

Checks if the event is running currently.

Returns
TypeNameDescription
booleanis_runningReturns true if the event is running currently, otherwise false.

#Event:once

sharedmenusource
function Event:once(handler: Event.Handler, priority: integer | nil)

Attaches a one-shot handler, detached right before it runs.

It can still be removed with detach using the same handler reference.

Parameters
NameTypeDescription
handlerEvent.HandlerThe callback or callable object, receives the call arguments.
priorityinteger | nilThe priority of the handler; handlers with a lower value run earlier. Defaults to 0.
Generated from the dreamwork meta branch.