1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00

Add stdnse.keys() for extracting keys from a table

This commit is contained in:
dmiller
2014-09-05 13:08:09 +00:00
parent 5c11f46bf0
commit b6e59efb4b
5 changed files with 21 additions and 42 deletions

View File

@@ -211,14 +211,6 @@ local function try_params(host, port, t)
end
end
local function keys(t)
local ret = {}
for k, _ in pairs(t) do
ret[#ret+1] = k
end
return ret
end
local function sorted_keys(t)
local ret = {}
for k, _ in pairs(t) do
@@ -709,8 +701,7 @@ function sorted_by_key(t)
local out = {}
setmetatable(out, {
__pairs = function(_)
local order = keys(t)
table.sort(order)
local order = sorted_keys(t)
return coroutine.wrap(function()
for i,k in ipairs(order) do
coroutine.yield(k, t[k])
@@ -753,7 +744,7 @@ action = function(host, port)
end
until next(threads) == nil
if #( keys(results) ) == 0 then
if #( stdnse.keys(results) ) == 0 then
return nil
end