From 964537219a525e577089a8b1581b590a4157f385 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Fri, 15 Oct 2021 00:51:18 +0800 Subject: [PATCH] =?UTF-8?q?FILE.load=E5=87=BD=E6=95=B0=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E8=AF=BB=E5=8F=96=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=BB=BA=E8=AE=AE=E4=BD=BF=E7=94=A8=E4=BB=A5=E9=98=B2=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=AF=86=E5=88=AB=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/file.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Zframework/file.lua b/Zframework/file.lua index f49e6bc1..5fdc2c7b 100644 --- a/Zframework/file.lua +++ b/Zframework/file.lua @@ -1,27 +1,30 @@ local fs=love.filesystem local FILE={} -function FILE.load(name) +function FILE.load(name,mode) if fs.getInfo(name)then local F=fs.newFile(name) if F:open'r'then local s=F:read() F:close() - if s:sub(1,6)=="return"then + if mode=='luaon'or not mode and s:sub(1,6)=="return{"then s=loadstring(s) if s then setfenv(s,{}) return s() end - elseif s:sub(1,1)=="["or s:sub(1,1)=="{"then + elseif mode=='json'or not mode and s:sub(1,1)=="["and s:sub(-1)=="]"or s:sub(1,1)=="{"and s:sub(-1)=="}"then local res=JSON.decode(s) if res then return res end - else + elseif mode=='string'or not mode then return s + else + MES.new("No file loading mode called "..tostring(mode)) end + else + MES.new('error',name.." "..text.loadError) end - MES.new('error',name.." "..text.loadError) end end function FILE.save(data,name,mode)