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