Skip to content

Collections · API

Registry

Stores values by name, and decides what registering a name twice does. The OverridePolicy passed to Registry.new picks it: “Throw” errors, “Warn” replaces the value and passes a message to WarnSink, and “Last” replaces it quietly.

local Tools = Collections.Registry.new({ Name = "Tools", OverridePolicy = "Throw" })
Tools:Register("hammer", 1)
print(Tools:Get("hammer"), Tools:Has("saw")) -- 1 false
Member Description
.new() Creates an empty registry.
:Register() Stores value under key.
:Unregister() Removes Key, and returns whether it was there.
:Get() Returns the value under Key, or nil.
:Has() Whether Key has a value.
:List() Returns every key, in no set order.
:Each() Returns an iterator over every key and value, in no set order.
:Clear() Removes every key.
:Seed() Registers each key and value of defaults, through the same OverridePolicy.
Validate Returns whether a value may be registered.
WarnSink Receives the message the “Warn” policy writes when it replaces a value.
Config Settings for Registry.new.
Registry The type Registry.new returns.
function Registry.new<V>(Config: Config<V>): Registry<V>

Creates an empty registry. Errors if OverridePolicy is not “Throw”, “Warn” or “Last”.

function Registry:Register(key: string, value: V)

Stores value under key. A key already there is handled by the OverridePolicy, and ValidateValue, when given, checks value first. Errors if key is not a string.

function Registry:Unregister<V>(Key: string): boolean

Removes Key, and returns whether it was there. Errors if Key is not a string.

function Registry:Get<V>(Key: string): V?

Returns the value under Key, or nil.

function Registry:Has<V>(Key: string): boolean

Whether Key has a value.

function Registry:List<V>(): { string }

Returns every key, in no set order.

function Registry:Each<V>(): () -> (string?, V?)

Returns an iterator over every key and value, in no set order.

function Registry:Clear<V>()

Removes every key.

function Registry:Seed<V>(defaults: { [string]: V })

Registers each key and value of defaults, through the same OverridePolicy.

export type Validate<V> = (value: V) -> (boolean, string?)

Returns whether a value may be registered. A second return, the reason, is ignored.

export type WarnSink = (message: string) -> ()

Receives the message the “Warn” policy writes when it replaces a value.

export type Config<V> = {
	Name: string,
	OverridePolicy: "Throw" | "Warn" | "Last",
	ValidateValue: Validate<V>?,
	WarnSink: WarnSink?,
}

Settings for Registry.new.

Field Type Description
Name string shown in error and warning messages
OverridePolicy "Throw" | "Warn" | "Last" what a second Register of a key does
ValidateValue Validate<V>? checks each value as it is registered, and errors when it fails
WarnSink WarnSink? receives the “Warn” policy’s messages, without which replacing is silent
export type Registry<V> = {
	Register: (self: Registry<V>, key: string, value: V) -> (),
	Unregister: (self: Registry<V>, key: string) -> boolean,
	Get: (self: Registry<V>, key: string) -> V?,
	Has: (self: Registry<V>, key: string) -> boolean,
	List: (self: Registry<V>) -> { string },
	Each: (self: Registry<V>) -> () -> (string?, V?),
	Clear: (self: Registry<V>) -> (),
	Seed: (self: Registry<V>, defaults: { [string]: V }) -> (),
}

The type Registry.new returns.

© 2026 PRMS Developer