U3D-XLua打印Lua表数据
使用的U3D版本是2018.4.36f1
-- 打印table 数据 keyword 打印起始关键词 | recurse 递归打印到第recurse层table | color = "ffff00"
function g_LuaUtil:Dump(data,keyword,recurse,color)
keyword = keyword or "g_LuaUtil:Dump"
recurse = recurse or 1
color = color or "ffff00"
local outStr = "<color=#"..color..">"..keyword .." = ".."</color>"
local getTableInfo
getTableInfo = function(tdata,twidth,recurseTime)
local tabWidth = twidth
if recurseTime and recurseTime > 0 then
tabWidth = tabWidth.."\t"
else
return type(tdata).."\n"
end
local szInfo = "\n"..twidth.."{\n<color=#"..color..">"
recurseTime = recurseTime - 1
for k,v in pairs(tdata) do
if type(v) == "number" or type(v) == "string" then
k = type(k) == "string" and '"'..k..'"' or k
v = type(v) == "string" and '"'..v..'"' or v
szInfo = szInfo ..tabWidth..k.." = "..v.."\n"
elseif type(v) == "boolean" then
szInfo = szInfo ..tabWidth..k.." = "..(v and "true" or " false").."\n"
elseif type(v) == "table" then
szInfo = szInfo .. tabWidth..k.." = "..getTableInfo(v,tabWidth,recurseTime)
else
szInfo = szInfo ..tabWidth..k.." = "..type(v).."\n"
end
end
szInfo = szInfo.. "</color>"..twidth.."}\n"
return szInfo
end
if type(data) == "table" then
outStr = outStr .. getTableInfo(data,"",recurse)
elseif type(data) == "string" or type(data) == "number" then
outStr = outStr..data.."\n"
elseif type(data) == "boolean" then
outStr = outStr..(data and "true" or "false").."\n"
else
outStr = outStr..type(data).."\n"
end
print(outStr)
end