lua中的Serialization

来源:互联网 发布:淘宝发货后修改物流 编辑:程序博客网 时间:2024/05/16 07:07
--Serialization   写成流可以和网络进行联通function serialize( o )    if type( o ) == "number" then        io.write(o)    elseif type(o) == "string" then        io.write("[[",o,"]]")    endenda = 'a, "hello lua" \\'--print(string.format("%q",a))--lua 5.1中的 [=[...]=]   --print([=['a, "hello lua" \\']=])--保存无环的tablefunction 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")    endend n_serialize{a =12,b ='lua'}--lua可以帮助你去扩展,简单的串行化;--lua脚本和txt
0 0
原创粉丝点击