- 代码:
- table.print=function(t)
local table,rg=table,{"{"}
for i,v in pairs(t) do
if type(i)“string” then i="’"…i…"’" end
if type(v)“string” then
table.insert(rg,"["…i…’]="’…v…’",–’…type(v))
elseif type(v)“number” then
table.insert(rg,"["…i…"]="…v…",–"…type(v))
elseif type(v)“function” then
table.insert(rg,"["…i…"]=function() end"…",–"…type(v))
elseif type(v)==“table” then
table.insert(rg,"["…i…"]="…table.print(v)…",–"…type(v))
end
end
table.insert(rg,"}")
return table.concat(rg,"\n")
end - 例子:
local z={}
for i=1,10 do
z[‘a’…i]=i
end
z[1]=100
z[2]={235,99,{"",function() end}}
z[3]=function(s) return s end
z[4
Lua:打印lua表
最新推荐文章于 2025-05-05 21:17:36 发布