Skip to content

tablelib

concat

function table.concat(list: table, sep?: string, i?: integer, j?: integer)
  -> string

Given a list where all elements are strings or numbers, returns the string list[i]..sep..list[i+1] ··· sep..list[j].

View documents

foreach

function table.foreach(list: any, callback: fun(key: string, value: any):<T>|nil)
  -> <T>|nil

Executes the given f over all elements of table. For each element, f is called with the index and respective value as arguments. If f returns a non-nil value, then the loop is broken, and this value is returned as the final value of foreach.

View documents

foreachi

function table.foreachi(list: any, callback: fun(key: string, value: any):<T>|nil)
  -> <T>|nil

Executes the given f over the numerical indices of table. For each index, f is called with the index and respective value as arguments. Indices are visited in sequential order, from 1 to n, where n is the size of the table. If f returns a non-nil value, then the loop is broken and this value is returned as the result of foreachi.

View documents

getn

function table.getn(list: <T>[])
  -> integer

Returns the number of elements in the table. This function is equivalent to #list.

View documents

insert

function table.insert(list: table, pos: integer, value: any)

Inserts element value at position pos in list.

View documents

maxn

function table.maxn(table: table)
  -> integer

Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices.

View documents

move

function table.move(a1: table, f: integer, e: integer, t: integer, a2?: table)
  -> a2: table

Moves elements from table a1 to table a2.

a2[t],··· =
a1[f],···,a1[e]
return a2

View documents

pack

function table.pack(...any)
  -> table

Returns a new table with all arguments stored into keys 1, 2, etc. and with a field "n" with the total number of arguments.

View documents

remove

function table.remove(list: table, pos?: integer)
  -> any

Removes from list the element at position pos, returning the value of the removed element.

View documents

sort

function table.sort(list: <T>[], comp?: fun(a: <T>, b: <T>):boolean)

Sorts list elements in a given order, in-place, from list[1] to list[#list].

View documents

unpack

function table.unpack(list: <T>[], i?: integer, j?: integer)
  -> ...<T>

Returns the elements from the given list. This function is equivalent to

    return list[i], list[i+1], ···, list[j]
By default, i is 1 and j is #list.

View documents