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


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
generated by LDoc 1.4.6 Last updated 2017-03-19 21:33:58