Lua文件操作和串行化

function n_serialize(data)
	if type(data)=="number" then
		io.write(data,"
")
	elseif type(data)=="string" then
		io.write(string.format("%q
",data))
	elseif type(data)=="table" then
		io.write("{
");
		for k,v in pairs(data) do
			io.write("	",k,"=")
			n_serialize(v)
			--io.write(",
")
		end
		io.write("}
")
	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()

原文地址:https://www.cnblogs.com/ggzone/p/10121265.html