现在的位置: 首页 > 综合 > 正文

打印lua内部结构的函数调用

2017年12月11日 ⁄ 综合 ⁄ 共 531字 ⁄ 字号 评论关闭
 function printTableInner(t,depth)
    for k,v in pairs(t) do
        if type(v) == "table" then
            print(string.rep(" ", depth)..'table,',k)
            printTableInner(v,depth+1)
        else
            print(string.rep(" ", depth)..k..","..v )
        end
    
    end
end

function printTable(t)

    for k,v in pairs(t) do
        if type(v) == "table" then
            print('table,',k)
            printTableInner(v,1)
        elseif type(v) == "function" then
            print('function,',k)
        else   
            print(k..",",v )
        end
    end
end

抱歉!评论已关闭.