Skip to content

Instantly share code, notes, and snippets.

@Srlion
Created January 9, 2019 14:08
Show Gist options
  • Save Srlion/41427627926054dd05066b625f1113d1 to your computer and use it in GitHub Desktop.
Save Srlion/41427627926054dd05066b625f1113d1 to your computer and use it in GitHub Desktop.
local COLOR_KEY = Color(0, 255, 0)
local COLOR_VALUE = Color(255, 255, 0)
local COLOR_DEFAULT = Color(255, 255, 255)
local COLOR_DOTS = Color(0, 0, 255)
do
local MsgC = MsgC
local istable = istable
local isstring = isstring
local tostring = tostring
local tabs
function PrintType(tbl)
if (!istable(tbl)) then
MsgC(COLOR_VALUE, tostring(tbl), "\n")
return
end
local first
if (!tabs) then
tabs = 0
first = true
end
local tabStr = ("| "):rep(tabs)
for k, v in pairs(tbl) do
local comma = next(tbl, k) != nil && "," || ""
if (isstring(k)) then
k = "\"" .. k .. "\""
else
k = tostring(k)
end
MsgC(COLOR_DOTS, tabStr, COLOR_DEFAULT, "[", COLOR_KEY, k, COLOR_DEFAULT, "] = ")
local _type = type(v)
if (istable(v)) then
if next(v) == nil then
MsgC(COLOR_DEFAULT, "{}")
else
MsgC(COLOR_DEFAULT, "{\n")
tabs = tabs + 1
PrintType(v)
tabs = tabs - 1
MsgC(COLOR_DOTS, tabStr, COLOR_DEFAULT, "}")
end
else
if (isstring(v)) then
v = "\"" .. v .. "\""
else
v = tostring(v)
end
MsgC(COLOR_VALUE, v)
end
MsgC(COLOR_DEFAULT, comma)
Msg("\n")
end
if (first) then
tabs = nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment