lua数据打印

Posted 那个妹子留步

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lua数据打印相关的知识,希望对你有一定的参考价值。

function getTableData(obj)
    local lua = ""
    local t = type(obj)
    if t == "number" then
        lua = lua .. obj
    elseif t == "boolean" then
        lua = lua .. tostring(obj)
    elseif t == "function" then
        lua = lua .. tostring(obj)
    elseif t == "string" then
        lua = lua .. string.format("%q", obj)
    elseif t == "table" then
        lua = lua .. "\\n"
        for k, v in pairs(obj) do
            if not  ExceptKey[k] then
                lua = lua .. "[" .. getTableData(k) .. "]=" .. getTableData(v) .. ",\\n"
            end
        end
        local metatable = getmetatable(obj)
        if metatable ~= nil and type(metatable.__index) == "table" then
            for k, v in pairs(metatable.__index) do
                if not  ExceptKey[k] then
                    lua = lua .. "[" .. getTableData(k) .. "]=" .. getTableData(v) .. ",\\n"
                end
            end
        end
        lua = lua .. ""
    elseif t == "nil" then
        return nil
    elseif t == "userdata" then
        lua = lua .. "\\n"
        local metatable = getmetatable(obj)
        if metatable ~= nil and type(metatable.__index) == "table" then
            for k, v in pairs(metatable.__index) do
                if not  ExceptKey[k] and not type(v) ~= "userdata" then
                    lua = lua .. "[" .. getTableData(k) .. "]=" .. getTableData(v) .. ",\\n"
                end
            end
        end
        lua = lua .. ""
    end
    return lua
end

以上是关于lua数据打印的主要内容,如果未能解决你的问题,请参考以下文章

lua数据打印

写一lua函数,能够遍历打印一个table数据,求代码!

Lua 打印在同一行

LUA:如何使用 io.write() 打印 Latin1 字符串?

quick lua 能用printf函数打印吗

Lua = 运算符作为打印