New loader

This commit is contained in:
qfx 2020-02-08 21:11:03 +02:00
parent b7c362b99e
commit 31317ad926

View File

@ -5,40 +5,23 @@ local elements = {}
local debugLoader = {} local debugLoader = {}
--Return level: 1--string; 2--chunk; 3--return value; default: element factory --Return level: 1--string; 2--chunk; 3--return value; default: element factory
local function loader(path) local function loader(path)
local succ = true
--File string
local fileContents, err = love.filesystem.read(path) local fileContents, err = love.filesystem.read(path)
local lastLoaded, status, func, succ, ret
if fileContents==nil then if fileContents then
print('Error loading ',path,':',tostring(err),', will continue watching!') lastLoaded = love.filesystem.getInfo(path).modtime
succ = false status, func = pcall(loadstring,fileContents)
end if not status then
print('Error compiling ',path,':',tostring(err),', will continue watching!')
local t, lastLoaded else
if succ then succ, ret = pcall(func,path)
t = love.filesystem.getInfo(path) end
lastLoaded = t['modtime']
end
--Chunk
local status, err
if succ then
status, err = pcall(loadstring,fileContents)
end
if status==false or status==nil then
print('Error compiling ',path,':',tostring(err),', will continue watching!')
succ = false
end
--Return values
local ret
if succ then
succ, ret = pcall(err,path)
if not succ then if not succ then
print('Error calling ',path,':',tostring(ret)) print('Error calling ',path,':',tostring(ret))
end end
else
print('Error loading ',path,':',tostring(err),', will continue watching!')
end end
return fileContents, err, ret, lastLoaded return fileContents, err, ret, lastLoaded
@ -77,7 +60,6 @@ function debugLoader.update(dt)
--If last save time differs then start reload sequence --If last save time differs then start reload sequence
local _, _, ret, lastLoaded = loader(elem[4]) local _, _, ret, lastLoaded = loader(elem[4])
local setfuncs = {} local setfuncs = {}
local reloader = function(setFunc) local reloader = function(setFunc)