Skip to content

TempTable

Inherits: LibTSMModule

Functions

Acquire

lua
function BaseType.TempTable.Acquire(...)
  -> table

Acquires a temporary table. Temporary tables are recycled tables which can be used instead of creating a new table every time one is needed for a defined lifecycle. This avoids relying on the garbage collector and improves overall performance.

Parameters:

NameTypeDescription
...anyAny number of values to insert into the table initially

Returns:

TypeDescription
table

AcquireWithOwner

lua
function BaseType.TempTable.AcquireWithOwner(owner, ...)
  -> table

Acquires a temporary table and takes ownership.

Parameters:

NameTypeDescription
ownertableThe owner
...anyAny number of values to insert into the table initially

Returns:

TypeDescription
table

ConcatAndRelease

lua
function BaseType.TempTable.ConcatAndRelease(tbl, sep, startIndex, endIndex)
  -> string

Concatenates the temporary table and releases it.

Parameters:

NameTypeDescription
tblstring[]The temporary table
sepstringThe separator
startIndexnumberThe first index to concat
endIndexnumberThe last index to concat

Returns:

TypeDescription
string

EnableLeakDebug

lua
function BaseType.TempTable.EnableLeakDebug()

Enables tracking of where temp tables are created from in order to debug leaks.

GetDebugInfo

lua
function BaseType.TempTable.GetDebugInfo()
  -> string[]

Gets debug information describing allocated and free temp tables.

Returns:

TypeDescription
string[]

Iterator

lua
function BaseType.TempTable.Iterator(tbl, numFields)
  -> fun():number, ...any, table, number

Iterators over a temporary table, releasing it when done. NOTE: This iterator must be run to completion and not be interrupted (i.e. with a break or return).

Parameters:

NameTypeDescription
tbltableThe temporary table to iterator over
numFieldsnumberThe number of fields to unpack with each iteration (defaults to 1)

Returns:

TypeDescription
fun():number, ...anyIterator with fields: index, {numFields...}
table
number

KeyIterator

lua
function BaseType.TempTable.KeyIterator(tbl)
  -> fun():number, ...any, table

Iterators over the keys of a temporary table, releasing it when done. NOTE: This iterator must be run to completion and not be interrupted (i.e. with a break or return).

Parameters:

NameTypeDescription
tbltableThe temporary table to iterator over

Returns:

TypeDescription
fun():number, ...anyIterator with fields: key
table

Release

lua
function BaseType.TempTable.Release(tbl)

Releases a temporary table. The temporary table will be returned to the pool and must not be accessed after being released.

Parameters:

NameTypeDescription
tbltableThe temporary table to release

ReleaseAllOwned

lua
function BaseType.TempTable.ReleaseAllOwned(owner)

Releases all owned temp tables.

Parameters:

NameTypeDescription
ownertableThe owner

TakeOwnership

lua
function BaseType.TempTable.TakeOwnership(tbl, owner)

Assigns ownership of a temp table.

Parameters:

NameTypeDescription
tbltableThe temp table
ownertableThe owner

UnpackAndRelease

lua
function BaseType.TempTable.UnpackAndRelease(tbl)
  -> ...<T>

Releases the temporary table and returns its unpacked values.

Parameters:

NameTypeDescription
tblT[]The temporary table to release and unpack

Returns:

TypeDescription
...<T>