Modul:TableTools: Unterschied zwischen den Versionen
add a fancy introductory comment
K (grammar) |
(add a fancy introductory comment) |
||
| Zeile 1: | Zeile 1: | ||
-- This module includes a number of functions | --[[ | ||
------------------------------------------------------------------------------------ | |||
-- TableTools -- | |||
-- -- | |||
-- This module includes a number of functions for dealing with Lua tables. -- | |||
-- It is a meta-module, meant to be called from other Lua modules, and should -- | |||
-- not be called directly from #invoke. -- | |||
------------------------------------------------------------------------------------ | |||
--]] | |||
local p = {} | local p = {} | ||
| Zeile 8: | Zeile 16: | ||
--[[ | --[[ | ||
----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ||
-- isPositiveInteger | -- isPositiveInteger | ||
-- | -- | ||
| Zeile 15: | Zeile 23: | ||
-- useful for determining whether a given table key is in the array part or the | -- useful for determining whether a given table key is in the array part or the | ||
-- hash part of a table. | -- hash part of a table. | ||
----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ||
--]] | --]] | ||
function p.isPositiveInteger(num) | function p.isPositiveInteger(num) | ||
| Zeile 26: | Zeile 34: | ||
--[[ | --[[ | ||
----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ||
-- getNumKeys | -- getNumKeys | ||
-- | -- | ||
-- This takes a table and returns an array containing the numbers of any numerical | -- This takes a table and returns an array containing the numbers of any numerical | ||
-- keys that have non-nil values, sorted in numerical order. | -- keys that have non-nil values, sorted in numerical order. | ||
----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ||
--]] | --]] | ||
function p.getNumKeys(t) | function p.getNumKeys(t) | ||
| Zeile 46: | Zeile 54: | ||
--[[ | --[[ | ||
----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ||
-- getAffixNums | -- getAffixNums | ||
-- | -- | ||
| Zeile 53: | Zeile 61: | ||
-- {a1 = 'foo', a3 = 'bar', a6 = 'baz'} and the prefix "a", getAffixNums will | -- {a1 = 'foo', a3 = 'bar', a6 = 'baz'} and the prefix "a", getAffixNums will | ||
-- return {1, 3, 6}. | -- return {1, 3, 6}. | ||
----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ||
--]] | --]] | ||
function p.getAffixNums(t, prefix, suffix) | function p.getAffixNums(t, prefix, suffix) | ||
| Zeile 72: | Zeile 80: | ||
--[[ | --[[ | ||
----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ||
-- compressSparseArray | -- compressSparseArray | ||
-- | -- | ||
| Zeile 78: | Zeile 86: | ||
-- while preserving the order, so that the array can be safely traversed with | -- while preserving the order, so that the array can be safely traversed with | ||
-- ipairs. | -- ipairs. | ||
----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ||
--]] | --]] | ||
function p.compressSparseArray(t) | function p.compressSparseArray(t) | ||
| Zeile 91: | Zeile 99: | ||
--[[ | --[[ | ||
----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ||
-- sparseIpairs | -- sparseIpairs | ||
-- | -- | ||
-- This is an iterator for sparse arrays. It can be used like ipairs, but can | -- This is an iterator for sparse arrays. It can be used like ipairs, but can | ||
-- handle nil values. | -- handle nil values. | ||
----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ||
--]] | --]] | ||
function p.sparseIpairs(t) | function p.sparseIpairs(t) | ||