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
Returns | Name | Description | |
---|---|---|---|
number | insert | Inserts element value at position in tbl | |
sort | Sorts the tbl elements in a given order, in-place, from tbl[1] to tbl[#tbl] | ||
table | move | Moves elements from the source_table to the dest_table | |
any | remove | Removes from tbl the element at position index , returning the value of the removed element | |
string | concat | Given a tbl where all elements are strings or numbers, returns the string with elements concatenated. |
insert
Inserts element value atposition
intbl
, shifting up the elementstbl[position], tbl[position + 1], ···, tbl[#tbl]
— Returns number.
local ret = table.insert(tbl, position?, value?)
Type | Parameter | Default | Description |
---|---|---|---|
table | tbl | Required parameter | The table to insert the variable into. |
number | position? | #tbl + 1 | The 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. |
any | value? |
| The variable to insert into the table. |
sort
Sorts thetbl
elements in a given order, in-place, fromtbl[1]
totbl[#tbl]
. Ifsorter
is given, then it must be a function that receives twotbl
elements and returns true when the first element must come before the second in the final order, so that, after the sort, i <= j impliesnot sorter(tbl[j], tbl[i])
. Ifsorter
is not given, then the standard Lua operator < is used instead.
Thesorter
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)
Type | Parameter | Default | Description |
---|---|---|---|
table | tbl | Required parameter | The table to sort. |
function | sorter | 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 thesource_table
to thedest_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?)
Type | Parameter | Default | Description |
---|---|---|---|
table | source_table | Required parameter | The source table from which the elements are to be moved. |
number | from | Required parameter | The start index of the source range from which the elements are to be moved. |
number | to | Required parameter | The end index of the source range until which the elements are to be moved. |
number | dest | 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. |
table | dest_table? | source_table | The destination table to which the elements are to be moved. By default, this is the same as the source table. |
remove
Removes fromtbl
the element at positionindex
, returning the value of the removed element.
Whenindex
is an integer between 1 and#tbl
, it shifts down the elementstbl[index + 1], tbl[index + 2], ···, tbl[#tbl]
and erases elementtbl[#tbl]
.
Theindex
can also be 0 when#tbl
is 0, or#tbl + 1
.
— Returns any.
local ret = table.remove(tbl, index)
Type | Parameter | Default | Description |
---|---|---|---|
table | tbl | Required parameter | The table to remove the value from. |
number | index | Required parameter | The index of the value to remove. |
concat
Given atbl
where all elements are strings or numbers, returns the stringtbl[start_pos] .. separator .. tbl[start_pos + 1] ... separator .. tbl[end_pos]
.
Ifstart_pos
is greater thanend_pos
, returns the empty string
— Returns string.
local ret = table.concat(tbl, separator?, start_pos?, end_pos?)