Module gears.table

Table module for gears

Functions

join (args) Join all tables given as parameters.
crush (t, set[, raw=false]) Override elements in the first table by the one in the second.
from_sparse (t) Pack all elements with an integer key into a new table While both lua and luajit implement __len over sparse table, the standard define it as an implementation detail.
hasitem (t, item) Check if a table has an item and return its key.
keys (t) Get a sorted table with all integer keys from a table
keys_filter (t, ...) Filter a tables keys for certain content types
reverse (t) Reverse a table
clone (t, deep) Clone a table
iterate (t, filter, start) Returns an iterator to cycle through, starting from the first element or the given index, all elements of a table that match a given criteria.
merge (t, set) Merge items from the one table to another one
map (f, tbl) Map a function to a table.


Functions

Methods
join (args)
Join all tables given as parameters. This will iterate all tables and insert all their keys into a new table.
  • args A list of tables to join

Returns:

    A new table containing all keys from the arguments.
crush (t, set[, raw=false])
Override elements in the first table by the one in the second.

Note that this method doesn’t copy entries found in __index.

  • t table the table to be overriden
  • set table the table used to override members of t
  • raw boolean Use rawset (avoid the metatable) (default false)

Returns:

    table t (for convenience)
from_sparse (t)
Pack all elements with an integer key into a new table While both lua and luajit implement __len over sparse table, the standard define it as an implementation detail.

This function remove any non numeric keys from the value set

  • t table A potentially sparse table

Returns:

    table A packed table with all numeric keys
hasitem (t, item)
Check if a table has an item and return its key.
  • t The table.
  • item The item to look for in values of the table.

Returns:

    The key were the item is found, or nil if not found.
keys (t)
Get a sorted table with all integer keys from a table
  • t the table for which the keys to get

Returns:

    A table with keys
keys_filter (t, ...)
Filter a tables keys for certain content types
  • t The table to retrieve the keys for
  • ... the types to look for

Returns:

    A filtered table with keys
reverse (t)
Reverse a table
  • t the table to reverse

Returns:

    the reversed table
clone (t, deep)
Clone a table
  • t the table to clone
  • deep Create a deep clone? (default: true)

Returns:

    a clone of t
iterate (t, filter, start)
Returns an iterator to cycle through, starting from the first element or the given index, all elements of a table that match a given criteria.
  • t
      the table to iterate
    
  • filter a function that returns true to indicate a positive match
  • start what index to start iterating from. Default is 1 (=> start of the table)
merge (t, set)
Merge items from the one table to another one
  • t table the container table
  • set table the mixin table

Returns:

    table Return t for convenience
map (f, tbl)
Map a function to a table. The function is applied to each value on the table, returning a table of the results.
  • f function the function to be applied to each value on the table
  • tbl table the container table whose values will be operated on

Returns:

    table Return a table of the results
generated by LDoc 1.4.6 Last updated 2030-01-01 00:00:00