Skip to content

Contextual

export type Contextual<T> = {
    type: "Contextual",
    now: (self) -> T,
    is: (self, newValue: T) -> {
        during: <R, A...>(self, callback: (A...) -> R, A...) -> R
    }
}

An object representing a widely-accessible value, which can take on different values at different times in different coroutines.

Non-standard type syntax

The above type definition uses self to denote methods. At time of writing, Luau does not interpret self specially.


Fields

type : "Contextual"

A type string which can be used for runtime type checking.


Methods

now -> T

function Contextual:now(): T

Returns the current value of this contextual. This varies based on when the function is called, and in what coroutine it was called.

is/during -> R

function Contextual:is(
    newValue: T
): {
    during: <R, A...>(
        self,
        callback: (A...) -> R,
        A...
    ) -> R
}

Runs the callback with the arguments A... and returns the value the callback returns (R). The Contextual will appear to be newValue in the callback, unless it's overridden by another :is():during() call.


Learn More

Back to top