বিষয়বস্তুতে চলুন

মডিউল:table/keysToList

উইকিঅভিধান, মুক্ত অভিধান থেকে

এই মডিউলের জন্য মডিউল:table/keysToList/নথি-এ নথিপত্র তৈরি করা হয়ে থাকতে পারে

local compare_module = "Module:compare"

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, [[Module:table/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