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 = {}
|
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
|
||||||
|
|
||||||
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
|
|
||||||
print('Error compiling ',path,':',tostring(err),', will continue watching!')
|
print('Error compiling ',path,':',tostring(err),', will continue watching!')
|
||||||
succ = false
|
else
|
||||||
|
succ, ret = pcall(func,path)
|
||||||
end
|
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user