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
相关文章推荐
- 超过lua上帝的语言
- lua for通过循环table一些差异
- Lua笔记9-再论函数
- lua学习笔记(1)
- Lua笔记8-模块和包
- lua lpeg
- C++ 和 lua代码互相调用
- Lua协程
- 【转】Lua coroutine 不一样的多线程编程思路
- [转]-Lua协程的实现
- lua table深度colone
- lua 判断字符串中引号,括号是否平衡
- lua 元表与元方法示例
- [转]lua面向对象编程之点号与冒号的差异详细比较
- 用LUA写一个日历
- LUA获取utf8字符串长度
- Lua绑定C++类
- quick-lua 游戏存档 GameState 方式
- 从C调用Lua
- Lua学习笔记(五):面向对象的实现