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
Lua 语言输出Table详细信息的实现
最新推荐文章于 2024-09-26 20:50:27 发布