file模块升级,支持非table数据直接保存为字符串
This commit is contained in:
@@ -12,11 +12,13 @@ function FILE.load(name)
|
|||||||
setfenv(s,{})
|
setfenv(s,{})
|
||||||
return s()
|
return s()
|
||||||
end
|
end
|
||||||
else
|
elseif s:sub(1,1)=="["or s:sub(1,1)=="{"then
|
||||||
local res=JSON.decode(s)
|
local res=JSON.decode(s)
|
||||||
if res then
|
if res then
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
return s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
LOG.print(name.." "..text.loadError,COLOR.red)
|
LOG.print(name.." "..text.loadError,COLOR.red)
|
||||||
@@ -24,19 +26,22 @@ function FILE.load(name)
|
|||||||
end
|
end
|
||||||
function FILE.save(data,name,mode)
|
function FILE.save(data,name,mode)
|
||||||
if not mode then mode=""end
|
if not mode then mode=""end
|
||||||
name=name
|
if type(data)=="table"then
|
||||||
if mode:find("l")then
|
if mode:find("l")then
|
||||||
data=DUMPTABLE(data)
|
data=DUMPTABLE(data)
|
||||||
if not data then
|
if not data then
|
||||||
LOG.print(name.." "..text.saveError.."dump error","error")
|
LOG.print(name.." "..text.saveError.."dump error","error")
|
||||||
return
|
return
|
||||||
|
end
|
||||||
|
else
|
||||||
|
data=JSON.encode(data)
|
||||||
|
if not data then
|
||||||
|
LOG.print(name.." "..text.saveError.."json error","error")
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
data=JSON.encode(data)
|
data=tostring(data)
|
||||||
if not data then
|
|
||||||
LOG.print(name.." "..text.saveError.."json error","error")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local F=fs.newFile(name)
|
local F=fs.newFile(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user