导航

Lua文件操作和串行化

Posted on 2015-08-05 10:36  ggzone  阅读(270)  评论(0编辑  收藏  举报
function n_serialize(data)
	if type(data)=="number" then
		io.write(data,"\n")
	elseif type(data)=="string" then
		io.write(string.format("%q\n",data))
	elseif type(data)=="table" then
		io.write("{\n");
		for k,v in pairs(data) do
			io.write("	",k,"=")
			n_serialize(v)
			--io.write(",\n")
		end
		io.write("}\n")
	else
	end
end


tbl={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()

版权声明:本文为博主原创文章,未经博主允许不得转载。