@@ -3,7 +3,7 @@ if not love.filesystem then
33 return setmetatable ({},{
44 __index = function (_ ,k )
55 error (" attempt to use FILE." .. k .. " , but FILE lib is not loaded (need love.filesystem)" )
6- end
6+ end ,
77 })
88end
99
@@ -49,13 +49,10 @@ function FILE.load(path,args,venv)
4949 ' string'
5050
5151 if mode == ' luaon' then
52- local lackReturn = s :match (" ^%s*{" )
53- if s :sub (1 ,1 )~= ' \27 ' then
54- s = " --[[" .. STRING .simplifyPath (path ).. ' ]]' .. (lackReturn and ' return' or ' ' ).. s
55- else
56- s = (lackReturn and ' return' or ' ' ).. s
57- end
58- local func ,err_mes = loadstring (s )
52+ local rtnPrefix = s :match (" ^%s*{" ) and " return" or " "
53+ print (rtnPrefix )
54+ s = rtnPrefix .. s
55+ local func ,err_mes = loadstring (s ,STRING .simplifyPath (path ))
5956 if func then
6057 setfenv (func ,venv or {})
6158 local res = func ()
@@ -64,8 +61,7 @@ function FILE.load(path,args,venv)
6461 error (" FILE.load: Decode error: " .. err_mes )
6562 end
6663 elseif mode == ' lua' then
67- if s :sub (1 ,1 )~= ' \27 ' then s = " --[[" .. STRING .simplifyPath (path ).. ' ]]' .. s end
68- local func ,err_mes = loadstring (s )
64+ local func ,err_mes = loadstring (s ,STRING .simplifyPath (path ))
6965 if func then
7066 local res = func ()
7167 return assert (res ," FILE.load: run error" )
@@ -93,8 +89,10 @@ function FILE.save(data,path,args)
9389 if type (data )== ' table' then
9490 local suc
9591 if STRING .sArg (args ,' -luaon' ) then
96- suc ,data = pcall (STRING .sArg (args ,' -expand' ) and TABLE .dump or TABLE .dumpDeflate ,data )
92+ local expand = STRING .sArg (args ,' -expand' )
93+ suc ,data = pcall (expand and TABLE .dump or TABLE .dumpDeflate ,data )
9794 assert (suc ," FILE.save: Luaon-encoding error: " .. data )
95+ data = (expand and " return " or " return" ).. data
9896 else
9997 suc ,data = pcall (JSON .encode ,data )
10098 assert (suc ," FILE.save: Json-encoding error: " .. data )
0 commit comments