如何在lua中打印一个数组(table)

来源:互联网 发布:win7软件停止运行 编辑:程序博客网 时间:2024/05/16 23:51

主体思路:通过递归遍历整个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))    endendlocal 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)


0 0