--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
lua中的Serialization
最新推荐文章于 2024-11-06 00:44:44 发布