TableHeapStr="" CurrentTableName="" function prt(x) local rst="" if type(x)=='number' or type(x)=='string' or type(x)=='function' or type(x)=='nil' then rst=rst..tostring(x) ..' ' end if type(x)=='table' and string.find(TableHeapStr,tostring(x))==nil then TableHeapStr=TableHeapStr..tostring(x) rst=rst..'\n'..CurrentTableName ..'{' for i,k in pairs(x) do if type(i)=='number' then rst=rst..prt(k) ..' ' else rst=rst..i..'= '..prt(k) ..' ' end CurrentTableName=i end rst=rst..'}\n' end return rst end testList={1,2,{33,44,55,{66,77,88} ,},prt} b=prt(_G) print( b )
标签:遍历,end,..,prt,lua,rst,table,TableHeapStr,type From: https://www.cnblogs.com/chenyalin/p/17155178.html