打印lua中的table
2014-06-22 10:54
232 查看
network = {
{name = "grauna", IP = "210.26.30.34"},
{name = "arraial", IP = "210.26.30.23"},
{name = "lua", IP = "210.26.23.12"},
{name = "derain", IP = "210.26.23.20"},
}
table.sort(network, function (a,b) return (a.name > b.name) end)
function print_lua_table (lua_table, indent)
indent = indent or 0
for k, v in pairs(lua_table) do
if type(k) == "string" then
k = string.format("%q", k)
end
local szSuffix = ""
if type(v) == "table" then
szSuffix = "{"
end
local szPrefix = string.rep(" ", indent)
formatting = szPrefix.."["..k.."]".." = "..szSuffix
if type(v) == "table" then
print(formatting)
print_lua_table(v, indent + 1)
print(szPrefix.."},")
else
local szValue = ""
if type(v) == "string" then
szValue = string.format("%q", v)
else
szValue = tostring(v)
end
print(formatting..szValue..",")
end
end
end
print_lua_table(network)
{name = "grauna", IP = "210.26.30.34"},
{name = "arraial", IP = "210.26.30.23"},
{name = "lua", IP = "210.26.23.12"},
{name = "derain", IP = "210.26.23.20"},
}
table.sort(network, function (a,b) return (a.name > b.name) end)
function print_lua_table (lua_table, indent)
indent = indent or 0
for k, v in pairs(lua_table) do
if type(k) == "string" then
k = string.format("%q", k)
end
local szSuffix = ""
if type(v) == "table" then
szSuffix = "{"
end
local szPrefix = string.rep(" ", indent)
formatting = szPrefix.."["..k.."]".." = "..szSuffix
if type(v) == "table" then
print(formatting)
print_lua_table(v, indent + 1)
print(szPrefix.."},")
else
local szValue = ""
if type(v) == "string" then
szValue = string.format("%q", v)
else
szValue = tostring(v)
end
print(formatting..szValue..",")
end
end
end
print_lua_table(network)
相关文章推荐
- 如何在lua中打印一个数组(table)
- 打印lua中的table
- [福利]Lua 打印table代码
- 如何打印出lua里table的内容
- Lua打印table升级版
- lua 打印 table 拷贝table
- Lua打印Table内容(日期)
- Lua中实现table的打印输出(print table)
- 【ulua入门】log(打印)lua中的table数据
- 树形打印lua table表
- 【步兵 lua】尾递归 打印table
- Lua打印Table内容(日期)
- 打印 Lua 的 table
- Lua打印table
- Lua中打印Table的方法
- cocos2dx 打印table,打印lua堆栈,重载lua代码
- 一个很棒的lua函数 用来打印table的内容
- 简单的写了一个打印Lua Table的函数
- Lua中实现table的打印输出(print table)
- lua 打印 table