Skip to content

Collections · API

Interner

Gives each distinct string a number, and turns the number back into the string. Numbers start at 1 and follow the order strings are first seen, and a string is never removed.

local Names = Collections.Interner.new()
local Id = Names:Intern("goblin")
print(Id, Names:KeyOf(Id)) -- 1 goblin
Member Description
.new() Creates an empty interner.
:Intern() Returns Key’s number, giving it the next one if it has none.
:KeyOf() Returns the string numbered Id, or nil if no string has that number.
:Count() How many distinct strings it holds.
Interner The type Interner.new returns.
function Interner.new(Config: { InitialCapacity: number? }?): Interner

Creates an empty interner.

function Interner:Intern(Key: string): number

Returns Key’s number, giving it the next one if it has none. Errors if Key is not a string.

function Interner:KeyOf(Id: number): string?

Returns the string numbered Id, or nil if no string has that number.

function Interner:Count(): number

How many distinct strings it holds.

export type Interner = {
	Intern: (self: Interner, Key: string) -> number,
	KeyOf: (self: Interner, Id: number) -> string?,
	Count: (self: Interner) -> number,
}

The type Interner.new returns.

© 2026 PRMS Developer