function look(Obj)
if type(Obj) ~= "table" then
print(Obj)
return
end
local function Save(Obj, Level)
local Blank = ""
for i = 1, Level do
Blank = Blank .. " "
end
for k,v in pairs(Obj) do
if tostring(k) ~= "" and v ~= Obj then
if type(v) ~= "table" then
print(Blank.. " [".. tostring(k).. "] = "..tostring(v))
else
print(Blank.. " [".. tostring(k).. "] = {")
Save(v, Level + 2)
print(Blank.." },")
end
end
end
end
print(" {")
Save(Obj, 1)
print(" }")
end
效果:
local tb_test={1,2,3,8,['ww']={11,33,{555,['num']=666,777}}}
循环生成缩进这部分可用 string.rep,应该能增强性能,对于调试影响不大,暂时这样用;另外想把传入打印的变量名打出来,如上面例子 tb_test={...},还没想到办法