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

lua中的Serialization

2015-07-22 16:52 295 查看
--Serialization   写成流可以和网络进行联通
function serialize( o )
if type( o ) == "number" then
io.write(o)
elseif type(o) == "string" then
io.write("[[",o,"]]")
end
end
a = 'a, "hello lua" \\'
--print(string.format("%q",a))
--lua 5.1中的 [=[...]=]
--print([=['a, "hello lua" \\']=])
--保存无环的table
function n_serialize( o )

if  type(o) == "number" then
io.write(o)

elseif type(o) == "string" then
io.write(string.format("%q",o))

elseif type(o) =="table" then
io.write("{\n")

for k,v in pairs(o) do
io.write("  ",k,"=")
n_serialize( v )
io.write(",\n")
end

io.write("}\n")
end
end
n_serialize{a =12,b ='lua'}
--lua可以帮助你去扩展,简单的串行化;
--lua脚本和txt
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: