FILE.load函数可以指定读取方法,建议使用以防自动识别失效
This commit is contained in:
@@ -1,27 +1,30 @@
|
|||||||
local fs=love.filesystem
|
local fs=love.filesystem
|
||||||
local FILE={}
|
local FILE={}
|
||||||
function FILE.load(name)
|
function FILE.load(name,mode)
|
||||||
if fs.getInfo(name)then
|
if fs.getInfo(name)then
|
||||||
local F=fs.newFile(name)
|
local F=fs.newFile(name)
|
||||||
if F:open'r'then
|
if F:open'r'then
|
||||||
local s=F:read()
|
local s=F:read()
|
||||||
F:close()
|
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)
|
s=loadstring(s)
|
||||||
if s then
|
if s then
|
||||||
setfenv(s,{})
|
setfenv(s,{})
|
||||||
return s()
|
return s()
|
||||||
end
|
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)
|
local res=JSON.decode(s)
|
||||||
if res then
|
if res then
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
else
|
elseif mode=='string'or not mode then
|
||||||
return s
|
return s
|
||||||
|
else
|
||||||
|
MES.new("No file loading mode called "..tostring(mode))
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
MES.new('error',name.." "..text.loadError)
|
||||||
end
|
end
|
||||||
MES.new('error',name.." "..text.loadError)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function FILE.save(data,name,mode)
|
function FILE.save(data,name,mode)
|
||||||
|
|||||||
Reference in New Issue
Block a user