PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

table

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 ( array list, string sep = "", int i = 1, int j = #list )

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 ( array t, function f )

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

void table.foreachi ( array t, function f )

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

number table.getn ( array t )

Returns the number of elements in the table passed

void table.insert ( array t, Variant value )

Appends the provided value to the end of the table.

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

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 ( array t, function comp = nil )

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.