Lua打印table中所有数据

function LuaHelps.PrintTable(t, name)
    local spaceAdd = 4
    local function getTableStr(t, name, space)
        local str = string.format("%s%s = {\n", string.rep(" ", space - spaceAdd), (name or "table"))
        local init = false
        for k, v in pairs(t) do
            if type(v) == "table" then
                str = str .. getTableStr(v, k, space + spaceAdd)
            else
                if type(v) == "string" and string.len(v) > 2 and string.sub(v, 1, 3) == "cs." then
                    init = true
                end
                str = str .. string.format("%s%s = %s\n", string.rep(" ", space), k, v)
            end
        end
        str = str .. string.rep(" ", space - spaceAdd) .. "}\n"
        return str
    end
    if (type(t) == "table") then
        print("\n" .. getTableStr(t, name, spaceAdd))
    else
        print(t)
    end
end

 

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读