lua自定义log

分享个log,可以打印各种类型,包括嵌套table


cc.exports.cwblog = function(...)
if config.debug==1 then
local text = ""
local xn = 0
local function textLineT(xn)
-- body
for i=1,xn do
text = text.."\t"
end
end

local function printTable(i,v)
-- body
if type(v) == "table" then
textLineT(xn)
xn = xn + 1
text = text..""..i..":Table{\n"
table.foreach(v,printTable)
textLineT(xn)
text = text.."}\n"
xn = xn - 1
elseif type(v) == nil then
textLineT(xn)
text = text..i..":nil\n"
else
textLineT(xn)
text = text..i..":"..tostring(v).."\n"
end
end
local function dumpParam(tab)
for i=1, #tab do
if tab[i] == nil then
text = text.."nil\t"
elseif type(tab[i]) == "table" then
xn = xn + 1
text = text.."\ntable{\n"
table.foreach(tab[i],printTable)
text = text.."\t}\n"
else
text = text..tostring(tab[i]).."\t"
end
end
end
local x = ...
if type(x) == "table" then
table.foreach(x,printTable)
else
dumpParam({...})
end
print(text)
end
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值