Module std.table
Extensions to the table module.
Functions
clone (t, nometa) | Make a shallow copy of a table, including any metatable. |
clone_rename (t, map) | Clone a table, renaming some keys. |
empty (t) | Return whether table is empty. |
invert (t) | Invert a table. |
keys (t) | Make the list of keys in table. |
merge (t, u) | Destructively merge another table's fields into table. |
new (x, t) | Make a table with a default value for unset keys. |
pack (...) | Turn a tuple into a list. |
ripairs (t) | An iterator like ipairs, but in reverse. |
size (t) | Find the number of elements in a table. |
sort (t, c) | Make table.sort return its result. |
totable (x) | Turn an object into a table according to __totable metamethod. |
values (t) | Make the list of values of a table. |
Functions
- clone (t, nometa)
-
Make a shallow copy of a table, including any metatable.
To make deep copies, use std.tree.clone.
Parameters:
- t
table
source table
- nometa boolean if non-nil don't copy metatable
Returns:
-
copy of table
- t
table
- clone_rename (t, map)
-
Clone a table, renaming some keys.
Parameters:
Returns:
-
copy of table
- empty (t)
-
Return whether table is empty.
Parameters:
- t table any table
Returns:
true
ift
is empty, otherwisefalse
- invert (t)
-
Invert a table.
Parameters:
- t
table
a table with
{k=v, ...}
Returns:
-
table
inverted table
{v=k, ...}
- t
table
a table with
- keys (t)
-
Make the list of keys in table.
Parameters:
- t table any table
Returns:
-
table
list of keys
- merge (t, u)
-
Destructively merge another table's fields into table.
Parameters:
Returns:
-
table
t
with fields fromu
merged in - new (x, t)
-
Make a table with a default value for unset keys.
Parameters:
- x
default entry value (default:
nil
) - t
table
initial table (default:
{}
)
Returns:
-
table
table whose unset elements are x
- x
default entry value (default:
- pack (...)
-
Turn a tuple into a list.
Parameters:
- ... tuple
Returns:
-
list
- ripairs (t)
-
An iterator like ipairs, but in reverse.
Parameters:
- t table any table
Returns:
- function iterator function
-
table
the table,
t
-
number
#t + 1
- size (t)
-
Find the number of elements in a table.
Parameters:
- t table any table
Returns:
-
number of non-nil values in
t
- sort (t, c)
-
Make table.sort return its result.
Parameters:
- t table unsorted table
- c function comparator function
Returns:
t
with keys sorted accordind toc
- totable (x)
-
Turn an object into a table according to __totable metamethod.
Parameters:
- x std.object object to turn into a table
Returns:
-
table
resulting table or
nil
- values (t)
-
Make the list of values of a table.
Parameters:
- t table any table
Returns:
-
table
list of values