Module:table/size
Itsura
- This module lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • sandbox
local next = next
local pairs = pairs
--[==[
This returns the size of a key/value pair table. If `raw` is set, then metamethods will be ignored, giving the true table size.
For arrays, it is faster to use `export.length`.]==]
return function(t, raw)
local i, iter, state, init = 0
if raw then
iter, state, init = next, t, nil
else
iter, state, init = pairs(t)
end
for _ in iter, state, init do
i = i + 1
end
return i
end