Lua文件操作和串行化

来源:互联网 发布:电脑日程提醒软件 编辑:程序博客网 时间:2024/05/25 08:13
function n_serialize(data)if type(data)=="number" thenio.write(data,"\n")elseif type(data)=="string" thenio.write(string.format("%q\n",data))elseif type(data)=="table" thenio.write("{\n");for k,v in pairs(data) doio.write("",k,"=")n_serialize(v)--io.write(",\n")endio.write("}\n")elseendendtbl={a=12,b="lua"}n_serialize(tbl)n_serialize(1)n_serialize("Hello World")local fw=assert(io.open("text.txt",'w'))fw:write("Hello World")fw:close()local fr=assert(io.open("text.txt",'r'))print(fr:read("a"))fr:close()

0 0