1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Allow outlib.sorted_by_key to specify sort function

This commit is contained in:
dmiller
2024-06-07 16:34:05 +00:00
parent a908872dae
commit 259d296b14

View File

@@ -32,12 +32,12 @@ local _ENV = {}
-- instead.
--@param t The table whose data should be used
--@return out A table that can be passed to pairs() to get sorted results
function sorted_by_key(t)
function sorted_by_key(t, sortfunc)
local out = {}
setmetatable(out, {
__pairs = function(_)
local order = keys(t)
sort(order)
sort(order, sortfunc)
return wrap(function()
for i,k in ipairs(order) do
yield(k, t[k])