Module table.extra

Table manipulation and transformation functions.

Release: $Id: table.extra.lua,v 1.2 2007/07/04 19:56:00 tomas Exp $

Functions

arraytorecord (tab, dest) Obtains a record from the elements of an array.
copyto (tab, dest) Copies values from one table to another (or a new one).
cycle (tab, n) Cyclic iterator over the arguments.
fullconcat (tab, kvsep, pairssep, kfilter, vfilter) Builds a list of pairs field=value, separated by commas.
invert (tab) Inverts the array part of a given table.
twostr (tab, ksep, vsep, kfilter, vfilter) Builds two lists, of keys and of values.


Functions

arraytorecord (tab, dest)
Obtains a record from the elements of an array.

Parameters

  • tab: Table representing the array.
  • dest: Table to receive the result (optional).

Return value:

Table representing a record.
copyto (tab, dest)
Copies values from one table to another (or a new one). The values could overwrite pre-existing ones.

Parameters

  • tab: Table with the values.
  • dest: Table where to store the values (default = {}).

Return value:

Table with the results (a new table, if none provided).
cycle (tab, n)
Cyclic iterator over the arguments. When reaching the end, it starts again over and over.

Parameters

  • tab: Table of elements to be traversed.
  • n: Number of arguments of tab (default = #tab).

Return value:

Function which return the next element.
fullconcat (tab, kvsep, pairssep, kfilter, vfilter)
Builds a list of pairs field=value, separated by commas. The '=' sign could be changed by the kvsep argument. The ',' could also be changed by the pairssep argument. Both the field and the value could be filtered by the kfilter and vfilter respectivelly.

Parameters

  • tab: Table of field=value pairs.
  • kvsep: String with key-value separator (default = '=').
  • pairssep: String with pairs separator (default = ',').
  • kfilter: Function to filter the keys (optional).
  • vfilter: Function to filter the values (optional).

Return value:

String with field=value pairs separated by ','.
invert (tab)
Inverts the array part of a given table.

Parameters

  • tab: Table to be inverted.
twostr (tab, ksep, vsep, kfilter, vfilter)
Builds two lists, of keys and of values. The values are written between "'", except the constant sql.NULL.

Parameters

  • tab: Table of key=value pairs.
  • ksep: String with key separator (default = ',').
  • vsep: String with value separator (default = ',').
  • kfilter: Function to filter the keys (optional).
  • vfilter: Function to filter the values (optional).

Return value:

Two strings; the first with a list of the fields and the second with a list of the values.

Valid XHTML 1.0!