Skip to content

Instantly share code, notes, and snippets.

@hodrigohamalho
Last active February 23, 2022 17:03
Show Gist options
  • Save hodrigohamalho/9bee22f53ed0e418b5c1b7448150a4fa to your computer and use it in GitHub Desktop.
Save hodrigohamalho/9bee22f53ed0e418b5c1b7448150a4fa to your computer and use it in GitHub Desktop.
Mandrake pra debug table Lua Script
function tprint (tbl, indent)
if not indent then indent = 0 end
local toprint = string.rep(" ", indent) .. "{\r\n"
indent = indent + 2
for k, v in pairs(tbl) do
toprint = toprint .. string.rep(" ", indent)
if (type(k) == "number") then
toprint = toprint .. "[" .. k .. "] : "
elseif (type(k) == "string") then
toprint = toprint .. k .. ": "
end
if (type(v) == "number") then
toprint = toprint .. v .. ",\r\n"
elseif (type(v) == "string") then
toprint = toprint .. "\"" .. v .. "\",\r\n"
elseif (type(v) == "table") then
toprint = toprint .. tprint(v, indent + 2) .. ",\r\n"
else
toprint = toprint .. "\"" .. tostring(v) .. "\",\r\n"
end
end
toprint = toprint .. string.rep(" ", indent-2) .. "}"
return toprint
end
ngx.say(tprint(token_info))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment