Module:table/size

From Linguifex
Revision as of 02:37, 8 April 2025 by wikt>Theknightwho (Protected "Module:table/size": Highly visible template/module ([Edit=Allow only template editors and administrators] (indefinite) [Move=Allow only template editors and administrators] (indefinite)))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:table/size/doc

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