Capil ka isi

Modul:table/size

Matan Wiktionary

Dokumentasi untuk modul ini dapat dibuat di Modul:table/size/doc

-- Imported from enwiktionary
-- Source: https://en.wiktionary.org/wiki/Module:table/size
-- License: CC BY-SA

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