Skip to content

Collections · API

GrowableBuffer

A list of numbers of one type, U8 to F64, that grows as you push. Indexes start at 0, and the list doubles its buffer when it runs out of room.

local Xs = Collections.GrowableBuffer.new({ Kind = "F64" })
Xs:Push(1.5)
Xs:Push(2.5)
print(Xs:Get(1), Xs:Length()) -- 2.5 2
Member Description
.new() Creates an empty list.
:Push() Appends Value and returns its index.
:Get() Returns the value at Index.
:Set() Writes Value at Index.
:Reserve() Grows the buffer to hold at least Amount values, so later pushes do not have to.
:Length() How many values have been pushed.
:Capacity() How many values fit before the buffer next grows.
:Raw() Returns the buffer and the length, for reading values directly.
GrowableBuffer The type GrowableBuffer.new returns.
function GrowableBuffer.new(
	Config: { Kind: string, InitialCapacity: number? }
): GrowableBuffer

Creates an empty list. Errors if Kind is not one of the five.

Parameter Type Description
Config { Kind: string, InitialCapacity: number? } Kind is “U8”, “U16”, “U32”, “F32” or “F64”, and InitialCapacity reserves room up front
function GrowableBuffer:Push(Value: number): number

Appends Value and returns its index. Raises and stores nothing when Value is not a number.

function GrowableBuffer:Get(Index: number): number

Returns the value at Index. Index is not checked against the length, and one past the buffer’s end errors.

function GrowableBuffer:Set(Index: number, Value: number)

Writes Value at Index. Like Get, it does not check Index against the length, so it cannot append.

function GrowableBuffer:Reserve(Amount: number)

Grows the buffer to hold at least Amount values, so later pushes do not have to.

function GrowableBuffer:Length(): number

How many values have been pushed.

function GrowableBuffer:Capacity(): number

How many values fit before the buffer next grows.

function GrowableBuffer:Raw(): (buffer, number)

Returns the buffer and the length, for reading values directly. A push past the capacity replaces the buffer, so take it again after one.

Returns Description
buffer
number the length
export type GrowableBuffer = {
	Push: (self: GrowableBuffer, Value: number) -> number,
	Get: (self: GrowableBuffer, Index: number) -> number,
	Set: (self: GrowableBuffer, Index: number, Value: number) -> (),
	Reserve: (self: GrowableBuffer, Amount: number) -> (),
	Length: (self: GrowableBuffer) -> number,
	Capacity: (self: GrowableBuffer) -> number,
	Raw: (self: GrowableBuffer) -> (buffer, number),
}

The type GrowableBuffer.new returns.

© 2026 PRMS Developer