主体思路:通过递归遍历整个table元素输出
local function ZCLOG(Lua_table)
-- do
-- return
-- end
local function define_print(_tab,str)
str = str .. " "
for k,v in pairs(_tab) do
if type(v) == "table" then
if not tonumber(k) then
print(str.. k .."{")
else
print(str .."{")
end
define_print(v,str)
print( str.."}")
else
print(str .. tostring(k) .. " " .. tostring(v))
end
end
end
if type(Lua_table) == "table" then
define_print(Lua_table," ")
else
print(tostring(Lua_table))
end
end
local a={
test1={1,2,3,4,5},
test2={
["周一"]=1,
["周二"]=2,
["周三"]=4,
["周四"]="3",
["周五"]="5",
},
test3={
[1]=1,
[2]=2,
[3]=4,
[4]="3",
[5]="5",
}
}
ZCLOG(a)
本文介绍了如何在Lua编程中利用递归方法遍历数组(table)的所有元素,并详细展示了如何将这些元素逐一打印出来。
970

被折叠的 条评论
为什么被折叠?



