lua中打印所以类型功能实现table嵌套table
来源:互联网 发布:未提交行1中的数据 编辑:程序博客网 时间:2024/06/06 14:02
lua中打印所以类型功能实现
本人测试 number、string、bool、nil、table嵌套table、userdata没问题 共享一下有什么问题请拍砖 代码如下
- cclog = function( ... )
- local tv = "\n"
- local xn = 0
- local function tvlinet(xn)
- -- body
- for i=1,xn do
- tv = tv.."\t"
- end
- end
- local function printTab(i,v)
- -- body
- if type(v) == "table" then
- tvlinet(xn)
- xn = xn + 1
- tv = tv..""..i..":Table{\n"
- table.foreach(v,printTab)
- tvlinet(xn)
- tv = tv.."}\n"
- xn = xn - 1
- elseif type(v) == nil then
- tvlinet(xn)
- tv = tv..i..":nil\n"
- else
- tvlinet(xn)
- tv = tv..i..":"..tostring(v).."\n"
- end
- end
- local function dumpParam(tab)
- for i=1, #tab do
- if tab[i] == nil then
- tv = tv.."nil\t"
- elseif type(tab[i]) == "table" then
- xn = xn + 1
- tv = tv.."\ntable{\n"
- table.foreach(tab[i],printTab)
- tv = tv.."\t}\n"
- else
- tv = tv..tostring(tab[i]).."\t"
- end
- end
- end
- local x = ...
- if type(x) == "table" then
- table.foreach(x,printTab)
- else
- dumpParam({...})
- -- table.foreach({...},printTab)
- end
- print(tv)
- end
使用示例如下代码
- local ttt = {23,aa=23,23,
- {bbb=23,"dsd",false,nil,
- {32,ccc="23dd",
- {23,"sdfsdf",
- {234,addd="23233jjjjsdOK"}
- }
- }
- },
- {dd = "sd",23},
- true
- }
- cclog(23,"sdf",ttt,"sdssssf",323223,false)
- Cocos2d: [LUA-print]
- 23 sdf
- table{
- 1:23
- 2:23
- 3:Table{
- 1:dsd
- 2:false
- 4:Table{
- 1:32
- 2:Table{
- 1:23
- 2:sdfsdf
- 3:Table{
- 1:234
- addd:23233jjjjsdOK
- }
- }
- ccc:23dd
- }
- bbb:23
- }
- 4:Table{
- 1:23
- dd:sd
- }
- 5:true
- aa:23
- }
- sdssssf 323223 false
0 0
- lua中打印所以类型功能实现table嵌套table
- lua中打印所以类型功能实现table嵌套table
- Lua中实现table的打印输出(print table)
- Lua中table类型的源码实现
- Lua中table类型的源码实现
- lua中table中嵌套table的使用
- Lua中打印Table的方法
- lua下打印有多层嵌套的table结构
- lua table 格式化打印
- 打印lua中的table
- lua 打印 table
- Lua打印table
- lua table打印
- Lua中table类型源码分析
- table中嵌套多层table
- LUA table类型
- lua的table类型
- lua调试打印table算法
- hdu 1114 Piggy-Bank
- OAuth认证原理
- 黑马程序员—OC—面向对象(二)
- Binary Tree Inorder Traversal
- Android中设定EditText的输入长度
- lua中打印所以类型功能实现table嵌套table
- ZOJ 3811 Untrusted Patrol 并查集
- C#中的值类型与引用类型
- iOS更换皮肤的思路与代码实现
- 黑马程序员—OC—类方法 && self
- 基于直方图均衡化的水下激光图像处理(MATLAB仿真)
- ZOJ1710
- LeetCode-Remove Nth Node From End of List
- 国企,私企与外企利弊