From d041b0e993bedfde6db8ce5bc6393eb320296011 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Thu, 15 Apr 2021 02:34:05 +0800 Subject: [PATCH] =?UTF-8?q?file=E6=A8=A1=E5=9D=97=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E9=9D=9Etable=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BF=9D=E5=AD=98=E4=B8=BA=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/file.lua | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Zframework/file.lua b/Zframework/file.lua index a57efafa..4453137f 100644 --- a/Zframework/file.lua +++ b/Zframework/file.lua @@ -12,11 +12,13 @@ function FILE.load(name) setfenv(s,{}) return s() end - else + elseif s:sub(1,1)=="["or s:sub(1,1)=="{"then local res=JSON.decode(s) if res then return res end + else + return s end end LOG.print(name.." "..text.loadError,COLOR.red) @@ -24,19 +26,22 @@ function FILE.load(name) end function FILE.save(data,name,mode) if not mode then mode=""end - name=name - if mode:find("l")then - data=DUMPTABLE(data) - if not data then - LOG.print(name.." "..text.saveError.."dump error","error") - return + if type(data)=="table"then + if mode:find("l")then + data=DUMPTABLE(data) + if not data then + LOG.print(name.." "..text.saveError.."dump error","error") + return + end + else + data=JSON.encode(data) + if not data then + LOG.print(name.." "..text.saveError.."json error","error") + return + end end else - data=JSON.encode(data) - if not data then - LOG.print(name.." "..text.saveError.."json error","error") - return - end + data=tostring(data) end local F=fs.newFile(name)