We use cookies on this site to enhance your user experience

Jul 02 2018, 3:58 PM PST 2 min

This library provides generic functions for table manipulation. It provides all its functions inside the global table variable. Most functions in the table library assume that the table represents an array or a list. For these functions, when we talk about the “length” of a table we mean the result of the length operator.



string table.concat(table list, string sep = "", int i = 1, int j = #list)

Description: Given a list where all elements are strings or numbers, returns the string list[i]..sep..list[i+1] ... sep..list[j]. The default value for sep is the empty string, the default for i is 1, and the default for j is #list. If i is greater than j, returns the empty string.


void table.foreach(table t, function f)

Description: Iterates over the provided table, passing the key and value of each iteration over to the provided function.


void table.foreachi(table t, function f)

Description: This is similar to table.foreach() except that index-value pairs are passed, not key-value pairs.


number table.getn(table t)

Description: Returns the number of elements in the table passed


void table.insert(table t, Variant value)

Description: Appends the provided value to the end of the table.


Variant table.remove(table list, number pos = #list)

Description: Removes from list the element at position pos, returning the value of the removed element. When pos is an integer between 1 and #list, it shifts down the elements list[pos+1], list[pos+2], ..., list[#list] and erases element list[#list]; The index pos can also be 0 when #list is 0, or #list + 1; in those cases, the function erases the element list[pos].


void table.sort(table t, function comp = nil)

Description: Sorts list elements in a given order, in-place, from list[1] to list[#list]. If comp is given, then it must be a function that receives two list elements and returns true when the first element must come before the second in the final order (so that not comp(list[i+1],list[i]) will be true after the sort). If comp is not given, then the standard Lua operator [less than] is used instead.