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
clone_rename (t, map)
Clone a table, renaming some keys.

Parameters:

  • t table source table
  • map table table {oldkey=newkey, ...}

Returns:

    copy of table
empty (t)
Return whether table is empty.

Parameters:

Returns:

    true if t is empty, otherwise false
invert (t)
Invert a table.

Parameters:

  • t table a table with {k=v, ...}

Returns:

    table inverted table {v=k, ...}
keys (t)
Make the list of keys in table.

Parameters:

Returns:

    table list of keys
merge (t, u)
Destructively merge another table's fields into table.

Parameters:

  • t table destination table
  • u table table with fields to merge

Returns:

    table t with fields from u 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
pack (...)
Turn a tuple into a list.

Parameters:

  • ... tuple

Returns:

    list
ripairs (t)
An iterator like ipairs, but in reverse.

Parameters:

Returns:

  1. function iterator function
  2. table the table, t
  3. number #t + 1
size (t)
Find the number of elements in a table.

Parameters:

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 to c
totable (x)
Turn an object into a table according to __totable metamethod.

Parameters:

Returns:

    table resulting table or nil
values (t)
Make the list of values of a table.

Parameters:

Returns:

    table list of values
generated by LDoc 1.4.0