当前位置:   article > 正文

lua dump

lua dump
--@param data 要打印的数据
 function dump( data )
    local str = "\"<var>\" = "
    if type(data) ~= "table" then
        print(str..tostring(data))
        return
    else
        print(str.."{")
    end
    for i, v in pairs(data) do
        dump_data(i, v, 1)
    end
    print("}")
end


function dump_data( key, data, depth )
    local head = ""
    for i = 1, depth do
        head = head.."\t"
    end
    if type(key) == "userdata" then 
        key = type(key)
    end
    if type(data) ~= "table" then
        print(head..key.." = "..tostring(data))
    else
        print(head..key.." = {")
        depth = depth + 1
        for i, v in pairs(data) do
            dump_data(i, v, depth)
        end
        print(head.."}")
    end
end


function test(  )
    local list = { 1, 2, 4, 5, test1 = "dddd", test2 = { 5, 6, 9, 9}}
    dump(list)
end


test()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/507726
推荐阅读
相关标签
  

闽ICP备14008679号