Skip to main content
Version: bleeding-edge 🩸

table

This library provides generic functions for table manipulation. It provides all its functions inside the table table.

🧑‍💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!

🎒 Examples

TODO Examples

🗿 Static Functions

ReturnsNameDescription
numberinsertInserts element value at position in tbl
sortSorts the tbl elements in a given order, in-place, from tbl[1] to tbl[#tbl]
tablemoveMoves elements from the source_table to the dest_table
anyremoveRemoves from tbl the element at position index, returning the value of the removed element
stringconcatGiven a tbl where all elements are strings or numbers, returns the string with elements concatenated.

insert

Inserts element value at position in tbl, shifting up the elements tbl[position], tbl[position + 1], ···, tbl[#tbl]

— Returns number.

local ret = table.insert(tbl, position?, value?)
TypeParameterDefaultDescription
tabletbl Required parameter The table to insert the variable into.
numberposition?#tbl + 1The position in the table to insert the variable. If the third argument is nil this argument becomes the value to insert at the end of given table.
anyvalue?The variable to insert into the table.

sort

Sorts the tbl elements in a given order, in-place, from tbl[1] to tbl[#tbl]. If sorter is given, then it must be a function that receives two tbl elements and returns true when the first element must come before the second in the final order, so that, after the sort, i <= j implies not sorter(tbl[j], tbl[i]). If sorter is not given, then the standard Lua operator < is used instead.

The sorter function must define a consistent order; more formally, the function must define a strict weak order. (A weak order is similar to a total order, but it can equate different elements for comparison purposes).

The sort algorithm is not stable: Different elements considered equal by the given order may have their relative positions changed by the sort.

table.sort(tbl, sorter)
TypeParameterDefaultDescription
tabletbl Required parameter The table to sort.
functionsorter Required parameter If specified, the function will be called with 2 parameters each. Return true in this function if you want the first parameter to come first in the sorted array.

move

Moves elements from the source_table to the dest_table, performing the equivalent to the following multiple assignment: dest_table[dest], ··· = a1[from], ···, source_table[to].

The destination range can overlap with the source range. The number of elements to be moved must fit in a Lua integer.

— Returns table.

local ret = table.move(source_table, from, to, dest, dest_table?)
TypeParameterDefaultDescription
tablesource_table Required parameter The source table from which the elements are to be moved.
numberfrom Required parameter The start index of the source range from which the elements are to be moved.
numberto Required parameter The end index of the source range until which the elements are to be moved.
numberdest Required parameter The index within the destination table where the moved elements should be inserted. If this is not specified, the moved elements will be inserted at the end of the table.
tabledest_table?source_tableThe destination table to which the elements are to be moved. By default, this is the same as the source table.

remove

Removes from tbl the element at position index, returning the value of the removed element.

When index is an integer between 1 and #tbl, it shifts down the elements tbl[index + 1], tbl[index + 2], ···, tbl[#tbl] and erases element tbl[#tbl].

The index can also be 0 when #tbl is 0, or #tbl + 1.

— Returns any.

local ret = table.remove(tbl, index)
TypeParameterDefaultDescription
tabletbl Required parameter The table to remove the value from.
numberindex Required parameter The index of the value to remove.

concat

Given a tbl where all elements are strings or numbers, returns the string tbl[start_pos] .. separator .. tbl[start_pos + 1] ... separator .. tbl[end_pos].

If start_pos is greater than end_pos, returns the empty string

— Returns string.

local ret = table.concat(tbl, separator?, start_pos?, end_pos?)
TypeParameterDefaultDescription
tabletbl Required parameter The table to concatenate.
stringseparator?""A separator to insert between strings
numberstart_pos?1The index to start at
numberend_pos?#tblThe index to end at