万能打印 ptable(...)免费
格式 : string = ptable( 任何类型 )
适用场景 : 二值化/日常打印/替代print()
function ptable(...)local function pta(t,L)local src,o="",""local L = L or 0 --[[记录递归次数]]local Tab = "\n"..string.rep("\t",L-1) --[[tab空格]]-- local Tab = "" --[[二值化打印]]local i = 0 --[[记录for循环次数]]for k,v in pairs(t) doif i > 0 then o = "," endi = i + 1local key,var="",""if type(k) == "string" then key = "[\'"..k.."\'] = " else key = "["..k.."] = " end--[[显示["key"],注释可隐藏]]if L == 0 then key = "" else key = src .. o .. Tab .. key end--[[初始值不显示Key]]if type(v) == "table" thensrc = key .. "{" ..pta(v,L+1).. Tab .."}"elseif type(v) == "string" thenvar = "'"..v.."'"elseif type(v) == "number" thenvar = velseif type(v) == "function" thenvar = "function"elseif type(v) == "boolean" thenif v then var = "true" else var = "false" endendsrc = key .. varendif L == 0 thenprint(src) --[[输出]]endendreturn srcendreturn pta({...}) --[[运行]]end
--[[数据测试]]local t = {{2,a=true,3},{{"nihao"},{{},{}},{3,{111},{222}}},3}ptable( t, {11111111111111111}, {"你好"})--[[支持多表同时打印,支持打印"boolean"值,支持打印二值化]]
二值化打印方法:


这么好用,你猜我会告诉你吗???

