FANDOM


p = {}
 
--- @brief 调试时打印变量的值
--- @param data 要打印的字符串
--- @param [max_level] table要展开打印的计数,默认nil表示全部展开
--- @param [prefix] 用于在递归时传递缩进,该参数不供用户使用于
--- @ref http://dearymz.blog.163.com/blog/static/205657420089251655186/
p.var_dump = function (data, max_level, prefix)
    local prev = ""
    if type(prefix) ~= "string" then
        prefix = ""
    end
    if type(data) ~= "table" then
        prev = prev .. (prefix .. tostring(data)) .. "\n"
    else
        prev = prev .. "table\n"
        if max_level ~= 0 then
            local prefix_next = prefix .. "    "
            prev = prev .. (prefix .. "{") .. "\n"
            for k,v in pairs(data) do
                prev = prev .. (prefix_next .. k .. " = ")
                if type(v) ~= "table" or (type(max_level) == "number" and max_level <= 1) then
                    if type(v) == "function" then v = "function{}" end
                    prev = prev .. (v) .. "\n"
                else
                    if max_level == nil then
                        prev = prev .. p.var_dump(v, nil, prefix_next) .. "\n"
                    else
                        prev = prev .. p.var_dump(v, max_level - 1, prefix_next) .. "\n"
                    end
                end
            end
            prev = prev .. (prefix .. "}") .. "\n"
        end
    end
    return prev
end
 
p.dumpObject = function (data, max_level)
    return p.var_dump(data, max_level or 5)
end
 
return p

您使用了广告屏蔽软件!


Wikia通过广告运营为用户提供免费的服务。我们对用户通过嵌入广告屏蔽软件访问网站进行了使用调整。

如果您使用了广告屏蔽软件,将无法使用我们的服务。请您移除广告屏蔽软件,以确保页面正常加载。

查看其他FANDOM

随机维基