-- 打印整个table数据
local function PrintTable (t)
local print_r_cache = {}
local str = ""
local function sub_print_r(t, indent)
if (print_r_cache[tostring(t)]) then
str = str .. indent .. "*" .. tostring(t)
else
print_r_cache[tostring(t)] = true
if (type(t) == "table") then
for pos, val in pairs(t) do
if (type(val) == "table") then
str = str .. indent .. "[" .. pos .. "] => " .. tostring(t) .. " {\n"
sub_print_r(val, indent .. string.rep(" ", string.len(pos) + 8))
str = str .. indent .. indent .. string.rep(" ", string.len(pos) + 6) .. "}\n"
elseif (type(val) == "string") then
str = str .. indent .. "[" .. pos .. '] => "' .. val .. '"\n'
else
str = str .. indent .. "[" .. pos .. "] => " .. tostring(val) .. "\n"
end
end
else
str = str .. indent .. tostring(t) .. "\n"
end
end
end
if (type(t) == "table") then
str = str .. tostring(t) .. " {"
sub_print_r(t, " ")
str = str .. tostring(t) .. "}"
else
sub_print_r(t, " ")
end
print(str)
end
table.PrintTable = PrintTable
PrintTable
最新推荐文章于 2020-07-13 16:18:53 发布