Перайсці да зместу

Модуль:Табліца/keysToList

З пляцоўкі Вікіслоўнік

Дакументацыю да гэтага модуля можна стварыць у Модуль:Табліца/keysToList/Дакументацыя

local compare_module = "Модуль:Параўнаць"

local pairs = pairs
local sort = table.sort

local compare
local function get_compare()
	compare, get_compare = require(compare_module), nil
	return compare
end

--[==[
Returns a list of the keys in a table, sorted using either the default `table.sort` function or a custom `key_sort` function.

If there are only numerical keys, [[Модуль:Табліца/numKeys]] is probably faster.]==]
return function(t, key_sort)
	local list, i = {}, 0
	for key in pairs(t) do
		i = i + 1
		list[i] = key
	end
	-- Use specified sort function, or otherwise `compare`.
	sort(list, key_sort == nil and (compare or get_compare()) or key_sort)
	return list
end