万能打印 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) do
if i > 0 then o = "," end
i = i + 1
local 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" then
src = key .. "{" ..pta(v,L+1).. Tab .."}"
else
if type(v) == "string" then
var = "'"..v.."'"
elseif type(v) == "number" then
var = v
elseif type(v) == "function" then
var = "function"
elseif type(v) == "boolean" then
if v then var = "true" else var = "false" end
end
src = key .. var
end
if L == 0 then
print(src) --[[输出]]
end
end
return src
end
return pta({...}) --[[运行]]
end
--[[数据测试]]
local t = {
{2,a=true,3},
{
{"nihao"},
{
{},
{}
},
{
3,
{111},
{222}
}
},
3
}
ptable( t, {11111111111111111}, {"你好"})
--[[支持多表同时打印,支持打印"boolean"值,支持打印二值化]]
二值化打印方法:
这么好用,你猜我会告诉你吗???