例子1 :
ableprint = function(data,cstring,deepIndex) --第二个参数可以为空,第三个参数不要手动添加,它是用来进行打印深度控制的。
if data == nil then
print("core.print data is nil");
end if deepIndex == nil then deepIndex = end
if cstring == nil then cstring = "" end local cs = cstring .. " ";
print(cstring .."{");
if(type(data)=="table") then
for k, v in pairs(data) do
if(type(v) == "table") then print(cs..tostring(k).." = ");
else print(cs..tostring(k).." = "..tostring(v)); end if(type(v)=="table") then if (deepIndex + ) < then --5就是控制的打印深度(你可以根据需要调整),以防数据结构中存在循环饮用(别以为不可能,我就遇到过)
zr.tableprint(v,cs,(deepIndex+));
else
print(cs.." {"..tostring(v).."}");
end
end
end
else
print(cs..tostring(data));
end
print(cstring .."}");
end
例子2:
function var_dump(data, max_level, prefix)
if type(prefix) ~= "string" then
prefix = ""
end
if type(data) ~= "table" then
print(prefix .. tostring(data))
else
print(data)
if max_level ~= then
local prefix_next = prefix .. " "
print(prefix .. "{")
for k,v in pairs(data) do
io.stdout:write(prefix_next .. k .. " = ")
if type(v) ~= "table" or (type(max_level) == "number" and max_level <= ) then
print(v)
else
if max_level == nil then
var_dump(v, nil, prefix_next)
else
var_dump(v, max_level - , prefix_next)
end
end
end
print(prefix .. "}")
end
end
end