json库使用方式调整

This commit is contained in:
MrZ626
2020-12-14 18:34:35 +08:00
parent f17724c7ef
commit 2381dca463
6 changed files with 69 additions and 90 deletions

View File

@@ -11,13 +11,15 @@ function FILE.load(name)
if s then
setfenv(s,{})
return s()
else
LOG.print(name.." "..text.loadError,COLOR.red)
end
else
local _,res=json.decode(s)
if _ then
local res=json.decode(s)
if res then
return res
else
LOG.print(name.." "..text.loadError..(mes or"unknown error"),COLOR.red)
LOG.print(name.." "..text.loadError,COLOR.red)
end
end
end
@@ -27,10 +29,9 @@ function FILE.save(data,name,mode,luacode)
name=name..".dat"
local _,mes
if not luacode then
_,data=json.encode(data)
if not _ then
res=json.encode(res)
if res then
LOG.print(name.." "..text.saveError..(mes or"json error"),"error")
return
end
else
data=dumpTable(data)

View File

@@ -304,7 +304,12 @@ do--json
function json.encode(val)
local a,b=pcall(encode,val)
if a then return b else return""end
if a then
return b
else
LOG.print(text.jsonError,"warn")
return
end
end
-------------------------------------------------------------------------------
@@ -532,7 +537,12 @@ do--json
end
function json.decode(str)
local a,b=pcall(decode,str)
if a then return b else return""end
if a then
return b
else
LOG.print(text.jsonError,"warn")
return
end
end
end