Difference between revisions of "Module:TableTools"
Jump to navigation
Jump to search
add a size function
en>Mr. Stradivarius (add a break in p.union to maybe save us cycling through a loop or two) |
en>Mr. Stradivarius (add a size function) |
||
Line 258: | Line 258: | ||
end | end | ||
end | end | ||
end | |||
--[[ | |||
------------------------------------------------------------------------------------ | |||
-- size | |||
-- | |||
-- This returns the size of a key/value pair table. It will also work on arrays, | |||
-- but for arrays it is more efficient to use the # operator. | |||
------------------------------------------------------------------------------------ | |||
--]] | |||
function p.size(t) | |||
local i = 0 | |||
for k in pairs(t) do | |||
i = i + 1 | |||
end | |||
return i | |||
end | end | ||
return p | return p |