Module:TableTools

--

-- This module includes a number of functions for dealing with Lua tables. -- -- @see Wikipedia:Module:TableTools for a similar module.

local p = {}

-- Returns a new table with all parameters stored into keys 1, 2, etc. and with -- a field `n` with the total number of parameters. Note that the resulting -- table may not be a sequence. -- -- @see 

function p.pack(...) return {n = select('#', ...), ...} end

-- Returns `true` if a given table is a sequence. -- -- @see 

function p.isSequence(t) local i = 1

for _ in pairs(t) do       if t[i] == nil then return false end

i = i + 1 end

return true end

-- Returns the number of elements in a table, even if it is not a sequence. -- -- @see 

function p.size(t) local i = 0

for _ in pairs(t) do       i = i + 1 end

return i end

return p

-- -- (Add categories here.)