mirror of
https://github.com/parnic/ice-hud.git
synced 2025-06-16 06:40:13 -05:00
Exporting works pretty well, but importing is rough (mostly because error messaging isn't quite in place, and it's not obvious that you have to close the window to execute the import). I found a generic json serializer, decided to adapt it to WoW, and it seems to work. But anyway, I saw this code sitting around and figured it wouldn't take too much work to get it in working order. I was mostly right.
38 lines
988 B
Lua
38 lines
988 B
Lua
local function table_print(tt, indent, done)
|
|
done = done or {}
|
|
indent = indent or 0
|
|
if type(tt) == "table" then
|
|
local sb = {}
|
|
for key, value in pairs(tt) do
|
|
table.insert(sb, string.rep(" ", indent)) -- indent it
|
|
if type(value) == "table" and not done[value] then
|
|
done[value] = true
|
|
table.insert(sb, key .. " = {\n");
|
|
table.insert(sb, table_print(value, indent + 2, done))
|
|
table.insert(sb, string.rep(" ", indent)) -- indent it
|
|
table.insert(sb, "}\n");
|
|
elseif "number" == type(key) then
|
|
table.insert(sb, string.format("\"%s\"\n", tostring(value)))
|
|
else
|
|
table.insert(sb, string.format(
|
|
"%s = \"%s\"\n", tostring(key), tostring(value)))
|
|
end
|
|
end
|
|
return table.concat(sb)
|
|
else
|
|
return tt .. "\n"
|
|
end
|
|
end
|
|
|
|
local function to_string(tbl)
|
|
if "nil" == type(tbl) then
|
|
return tostring(nil)
|
|
elseif "table" == type(tbl) then
|
|
return table_print(tbl)
|
|
elseif "string" == type(tbl) then
|
|
return tbl
|
|
else
|
|
return tostring(tbl)
|
|
end
|
|
end
|