Commit 2c232099 authored by Marek Vavruša's avatar Marek Vavruša

lua/sandbox: print non-printable characters in hex, text elide

parent 35411697
......@@ -151,18 +151,31 @@ function table_print (tt, indent, done)
done = done or {}
indent = indent or 0
result = ""
-- Convert to printable string (escape unprintable)
local function printable(value)
value = tostring(value)
local bytes = {}
for i = 1, #value do
local c = string.byte(value, i)
if c >= 0x20 and c < 0x7f then table.insert(bytes, string.char(c))
else table.insert(bytes, '\\'..tostring(c))
end
if i > 50 then table.insert(bytes, '...') break end
end
return table.concat(bytes)
end
if type(tt) == "table" then
for key, value in pairs (tt) do
result = result .. string.rep (" ", indent)
if type (value) == "table" and not done [value] then
done [value] = true
result = result .. string.format("[%s] => {\n", tostring (key))
result = result .. string.format("[%s] => {\n", printable (key))
result = result .. table_print (value, indent + 4, done)
result = result .. string.rep (" ", indent)
result = result .. "}\n"
else
result = result .. string.format("[%s] => %s\n",
tostring (key), tostring(value))
tostring (key), printable(value))
end
end
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment