mirror of
https://github.com/nmap/nmap.git
synced 2025-12-27 09:59:04 +00:00
With debugging, NSE prints out the script-args string and the pretty printed
final script-args table. The rationale is, unfortunately shells interpret quotes differently and so it can be hard to tell exactly what NSE ends up seeing/producing. [Some discussion in #nmap on Freenode resulted in this addition.]
This commit is contained in:
@@ -24,6 +24,7 @@ local require = require;
|
||||
local select = select
|
||||
local setmetatable = setmetatable;
|
||||
local tonumber = tonumber;
|
||||
local tostring = tostring;
|
||||
local type = type
|
||||
|
||||
local ceil = math.ceil
|
||||
@@ -1159,4 +1160,39 @@ function output_table ()
|
||||
return setmetatable({}, mt)
|
||||
end
|
||||
|
||||
--- A pretty printer for Lua objects.
|
||||
--
|
||||
-- Takes an object (usually a table) and prints it using the
|
||||
-- printer function. The printer function takes a sole string
|
||||
-- argument and will be called repeatedly.
|
||||
--
|
||||
-- @args obj The object to pretty print.
|
||||
-- @args printer The printer function.
|
||||
function pretty_printer (obj, printer)
|
||||
if printer == nil then printer = print end
|
||||
|
||||
local function aux (obj, spacing)
|
||||
local t = type(obj)
|
||||
if t == "table" then
|
||||
printer "{\n"
|
||||
for k, v in pairs(obj) do
|
||||
local spacing = spacing.."\t"
|
||||
printer(spacing)
|
||||
printer "["
|
||||
aux(k, spacing)
|
||||
printer "] = "
|
||||
aux(v, spacing)
|
||||
printer ",\n"
|
||||
end
|
||||
printer(spacing.."}")
|
||||
elseif t == "string" then
|
||||
printer(format("%q", obj))
|
||||
else
|
||||
printer(tostring(obj))
|
||||
end
|
||||
end
|
||||
|
||||
return aux(obj, "")
|
||||
end
|
||||
|
||||
return _ENV;
|
||||
|
||||
Reference in New Issue
Block a user