我是靠谱客的博主 俊逸嚓茶,这篇文章主要介绍使用lua实现php的var_dump()函数功能,现在分享给大家,希望可以做个参考。

习惯了php中的var_dump()函数,而如今写lua的时候总习惯使用var_dump()函数,于是就自己动手写了一个类似功能的var_dump()函数。

复制代码 代码如下:

function var_dump(data, max_level, prefix)  
    if type(prefix) ~= "string" then  
        prefix = "" 
    end  
    if type(data) ~= "table" then  
        print(prefix .. tostring(data))  
    else 
        print(data)  
        if max_level ~= 0 then  
            local prefix_next = prefix .. "    " 
            print(prefix .. "{")  
            for k,v in pairs(data) do 
                io.stdout:write(prefix_next .. k .. " = ")  
                if type(v) ~= "table" or (type(max_level) == "number" and max_level <= 1) then  
                    print(v)  
                else 
                    if max_level == nil then  
                        var_dump(v, nil, prefix_next)  
                    else 
                        var_dump(v, max_level - 1, prefix_next)  
                    end  
                end  
            end  
            print(prefix .. "}")  
        end  
    end  
end 

最后

以上就是俊逸嚓茶最近收集整理的关于使用lua实现php的var_dump()函数功能的全部内容,更多相关使用lua实现php内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(225)

评论列表共有 0 条评论

立即
投稿
返回
顶部