Module sintra.table
Table manipulation and transformation functions.
Info:
- Release: 1.20
Functions
| array2record (tab, dest) | Obtains a record from the elements of an array. |
| invert (tab) | Inverts the array part of a given table. |
| copyto (tab, dest) | Copies values from one table to another (or a new one). |
| copyarrayto (array, dest) | Copies values from one array to another (or to a new one). |
| mapfilter (tab, tofrom, dest) | Copies values from a table to another, converting its keys. |
| swapkeyval (tab, dest) | Swaps the key-value pairs from a table to another. |
| cycle (tab, n) | Cyclic iterator over the arguments. |
| set2array (tab, dest) | Copies keys as elements of an array, in an undetermined order. |
| dnext (tab, i) | Similar to next for arrays but returns the i-th element and the value associated to it in the same table. |
| dpairs (tkeys, tvalues) | Iterator of doubled-indexed table. |
| rec2tagarray (tab, dest) | Convert a record-like table to an array of tables each with a 'tag' entry containing the original key and with a [1] entry containing the value corresponding the original key. |
| vtostring (val) | Serializa um valor Lua de qualquer tipo. |
| tostring (tab, indent, ac) | Serializa tabelas Lua sem ciclos. |
| vserialize (val, outf) | Serializa um valor Lua de qualquer tipo. |
| serialize (tab, outf) | Serializa uma tabela Lua que não possua ciclos e cujas chaves e elementos não podem ser dos tipos userdata nem thread. |
| tofile (tab, file_or_name) | Serializa uma tabela Lua que não possua ciclos e cujas chaves e elementos não podem ser dos tipos userdata nem thread, salvando em um arquivo. |
Functions
- array2record (tab, dest)
-
Obtains a record from the elements of an array.
Parameters:
- tab Table representing the array.
- dest Table to receive the result (optional).
Returns:
-
Table representing a record.
- invert (tab)
-
Inverts the array part of a given table.
Parameters:
- tab Table to be inverted.
- 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 = {}).
Returns:
-
Table with the results (a new table, if none provided).
- copyarrayto (array, dest)
-
Copies values from one array to another (or to a new one).
The values are appended at the end of the given array.
Parameters:
- array Table with the values.
- dest Table where to store the values (default = {}).
Returns:
-
Table with the results (a new table, if none provided).
- mapfilter (tab, tofrom, dest)
-
Copies values from a table to another, converting its keys.
Thus:
dest[mkey] = source[mvalue]
Or:
dest[mkey] = mvalue (source)
Parameters:
- tab Table source.
- tofrom Table with converting rules: each key on tofrom should be the name of the key on the destination table and the corresponding value on tofrom should be the key on the source table; values could be functions which receive the whole source table as argument.
- dest Table where to store the values (default = {}).
Returns:
-
Table with the results (a new table, if none provided).
- swapkeyval (tab, dest)
-
Swaps the key-value pairs from a table to another.
Parameters:
- tab Table source.
- dest Table where to store the values (default = {}).
Returns:
-
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).
Returns:
-
Function which return the next element.
- set2array (tab, dest)
-
Copies keys as elements of an array, in an undetermined order.
Parameters:
- tab Table of elements.
- dest Table where to store the values as array elements (default = {}).
Returns:
-
Table with the results (a new table, if none provided).
- dnext (tab, i)
-
Similar to next for arrays but returns the i-th element and the value
associated to it in the same table.
It makes sense over doubled-indexed tables which have an array part with
the order of the keys of the record part.
Parameters:
- tab Table with numeric keys whose values are other keys.
- i Integer index of the key.
Returns:
- Number with new index
- tab[i]
- tab[ tab[i] ]
- dpairs (tkeys, tvalues)
-
Iterator of doubled-indexed table.
Parameters:
- tkeys Table with numeric keys whose values are other keys.
- tvalues Table with the values corresponding to the keys (it is possible that a key has no corresponding value).
Returns:
-
Iterator that returns key-value pairs according to the order of
the keys in the numeric entries.
- rec2tagarray (tab, dest)
-
Convert a record-like table to an array of tables each with a 'tag' entry
containing the original key and with a [1] entry containing the value
corresponding the original key.
Parameters:
- tab Table representing a record.
- dest Table where to store the values as array elements (default = {}).
Returns:
-
Table with the resulting array of tables.
- vtostring (val)
-
Serializa um valor Lua de qualquer tipo.
Parameters:
- val Qualquer valor Lua a ser transformado em string.
Returns:
-
String com o valor serializado.
- tostring (tab, indent, ac)
-
Serializa tabelas Lua sem ciclos.
Parameters:
- tab Tabela a ser serializada.
- indent String com texto usado para indentação.
- ac String que acumula a indentação de acordo com os níveis de tabelas.
Returns:
-
String com a tabela serializada.
- vserialize (val, outf)
-
Serializa um valor Lua de qualquer tipo.
Se for uma tabela, chama sintra.table.serialize para tratar recursivamente.
Parameters:
- val Qualquer valor Lua a ser transformado em string.
- outf Função de escrita da saída (deve receber uma string).
- serialize (tab, outf)
-
Serializa uma tabela Lua que não possua ciclos e cujas chaves e elementos
não podem ser dos tipos userdata nem thread.
Parameters:
- tab Tabela a ser serializada.
- outf Função de escrita da saída (deve receber uma string).
- tofile (tab, file_or_name)
-
Serializa uma tabela Lua que não possua ciclos e cujas chaves e elementos
não podem ser dos tipos userdata nem thread, salvando em um arquivo.
Parameters:
- tab Tabela a ser serializada.
- file_or_name String (com o nome do arquivo), função (de escrita) ou arquivo previamente aberto. Se o segundo parâmetro for o nome de um arquivo, este será aberto para atualização ("w+") e a palavra "return " será escrita antes da serialização da tabela e o arquivo será fechado no final; se o segundo parâmetro for um userdata, apenas será usado o método write para escrever seu conteúdo, ficando a cargo do programador fechar o arquivo.