您的位置:首页 > 编程语言 > Lua

Lua 语言输出Table详细信息的实现

2015-08-09 15:07 423 查看
function PrintTable(tbl, f, bShowSquare)
if type(f) ~= "function" and f ~= nil then
error("The second argument %s should be a function", tostring(f))
end
    if type(b) ~= "boolean" and b ~= nil then
error("The third argument %s should be a boolean", tostring(b))
end
p = f or io.write
bShowSquare = bShowSquare or false
if type(tbl) == "number" or
type(tbl) == "function" or
type(tbl) == "boolean" or
type(tbl) == "nil" then
p(tostring(tbl))
elseif type(tbl) == "string" then
p(string.format("%q",o))
elseif type(tbl) == "table" then
p("{\n")
for k,v in pairs(tbl) do
            if bShowSquare then p("[") end
PrintTable(k, p, b)

if bShowSquare then p("]") end
p(" = ")
PrintTable(v, p, b)
p(",\n")
end
p("}")
end
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: