LuaXml 小系列1
1 -- saves a Lua var as xml file 2 function save(var,filename) 3 if not var then return end 4 if not filename or #filename==0 then return end 5 local file = base.io.open(filename,"w") 6 file:write("<?xml version=\"1.0\"?>\n<!-- file \"",filename, "\", generated by LuaXML -->\n\n") 7 file:write(str(var)) 8 base.io.close(file) 9 end
LuaXml位置 C:\Program Files\Lua\5.1\lua。
Lua默认的保存为xml函数中没有encoding=GBK,防止出现乱码或者中文不能识别的情况,修改后的代码如下:
function save(var,filename) if not var then return end if not filename or #filename==0 then return end local file = base.io.open(filename,"w") file:write("<?xml version=\"1.0\" encoding=\"GBK\" ?>\n\n") file:write(str(var)) base.io.close(file) end