mirror of
https://github.com/usysrc/LICK.git
synced 2024-11-24 16:44:21 +00:00
refactor: ♻️ cleaned up local variables
This commit is contained in:
parent
05b0a9ab3c
commit
bc83e9484d
62
lick.lua
62
lick.lua
@ -1,7 +1,7 @@
|
|||||||
-- lick.lua
|
-- lick.lua
|
||||||
--
|
--
|
||||||
-- simple LIVECODING environment for Löve
|
-- simple LIVECODING environment for Löve
|
||||||
-- overwrites love.run, pressing all errors to the terminal/console
|
-- overwrites love.run, pressing all errors to the terminal/console or overlays it
|
||||||
|
|
||||||
local lick = {}
|
local lick = {}
|
||||||
lick.file = "main.lua"
|
lick.file = "main.lua"
|
||||||
@ -9,9 +9,13 @@ lick.debug = false
|
|||||||
lick.reset = false
|
lick.reset = false
|
||||||
lick.clearFlag = false
|
lick.clearFlag = false
|
||||||
lick.sleepTime = love.graphics.newCanvas and 0.001 or 1
|
lick.sleepTime = love.graphics.newCanvas and 0.001 or 1
|
||||||
|
lick.showReloadMessage = true
|
||||||
|
|
||||||
|
local drawok_old, updateok_old, loadok_old
|
||||||
local last_modified = 0
|
local last_modified = 0
|
||||||
|
local debugoutput = nil
|
||||||
|
|
||||||
|
-- Error handler wrapping for pcall
|
||||||
local function handle(err)
|
local function handle(err)
|
||||||
return "ERROR: " .. err
|
return "ERROR: " .. err
|
||||||
end
|
end
|
||||||
@ -21,69 +25,72 @@ local function load()
|
|||||||
last_modified = 0
|
last_modified = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update(dt)
|
local function checkFileUpdate()
|
||||||
local info = love.filesystem.getInfo(lick.file)
|
local info = love.filesystem.getInfo(lick.file)
|
||||||
if info and last_modified < info.modtime then
|
if not info or last_modified >= info.modtime then
|
||||||
|
return
|
||||||
|
end
|
||||||
last_modified = info.modtime
|
last_modified = info.modtime
|
||||||
success, chunk = pcall(love.filesystem.load, lick.file)
|
local success, chunk = pcall(love.filesystem.load, lick.file)
|
||||||
if not success then
|
if not success then
|
||||||
print(tostring(chunk))
|
print(tostring(chunk))
|
||||||
lick.debugoutput = chunk .. "\n"
|
debugoutput = chunk .. "\n"
|
||||||
end
|
end
|
||||||
ok,err = xpcall(chunk, handle)
|
local ok, err = xpcall(chunk, handle)
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
print(tostring(err))
|
print(tostring(err))
|
||||||
if lick.debugoutput then
|
if debugoutput then
|
||||||
lick.debugoutput = (lick.debugoutput .."ERROR: ".. err .. "\n" )
|
debugoutput = (debugoutput .. "ERROR: " .. err .. "\n")
|
||||||
else
|
else
|
||||||
lick.debugoutput = err .. "\n"
|
debugoutput = err .. "\n"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print("CHUNK LOADED\n")
|
if lick.showReloadMessage then print("CHUNK LOADED\n") end
|
||||||
lick.debugoutput = nil
|
debugoutput = nil
|
||||||
end
|
end
|
||||||
if lick.reset then
|
if lick.reset then
|
||||||
loadok, err = xpcall(love.load, handle)
|
local loadok, err = xpcall(love.load, handle)
|
||||||
if not loadok and not loadok_old then
|
if not loadok and not loadok_old then
|
||||||
print("ERROR: " .. tostring(err))
|
print("ERROR: " .. tostring(err))
|
||||||
if lick.debugoutput then
|
if debugoutput then
|
||||||
lick.debugoutput = (lick.debugoutput .."ERROR: ".. err .. "\n" )
|
debugoutput = (debugoutput .. "ERROR: " .. err .. "\n")
|
||||||
else
|
else
|
||||||
lick.debugoutput = err .. "\n"
|
debugoutput = err .. "\n"
|
||||||
end
|
end
|
||||||
loadok_old = not loadok
|
loadok_old = not loadok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
updateok, err = pcall(love.update,dt)
|
local function update(dt)
|
||||||
|
checkFileUpdate()
|
||||||
|
local updateok, err = pcall(love.update, dt)
|
||||||
if not updateok and not updateok_old then
|
if not updateok and not updateok_old then
|
||||||
print("ERROR: " .. tostring(err))
|
print("ERROR: " .. tostring(err))
|
||||||
if lick.debugoutput then
|
if debugoutput then
|
||||||
lick.debugoutput = (lick.debugoutput .."ERROR: ".. err .. "\n" )
|
debugoutput = (debugoutput .. "ERROR: " .. err .. "\n")
|
||||||
else
|
else
|
||||||
lick.debugoutput = err .. "\n"
|
debugoutput = err .. "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
updateok_old = not updateok
|
updateok_old = not updateok
|
||||||
end
|
end
|
||||||
|
|
||||||
local function draw()
|
local function draw()
|
||||||
drawok, err = xpcall(love.draw, handle)
|
local drawok, err = xpcall(love.draw, handle)
|
||||||
if not drawok and not drawok_old then
|
if not drawok and not drawok_old then
|
||||||
print(tostring(err))
|
print(tostring(err))
|
||||||
if lick.debugoutput then
|
if debugoutput then
|
||||||
lick.debugoutput = (lick.debugoutput .. err .. "\n" )
|
debugoutput = (debugoutput .. err .. "\n")
|
||||||
else
|
else
|
||||||
lick.debugoutput = err .. "\n"
|
debugoutput = err .. "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if lick.debug and lick.debugoutput then
|
if lick.debug and debugoutput then
|
||||||
love.graphics.setColor(1, 1, 1, 0.8)
|
love.graphics.setColor(1, 1, 1, 0.8)
|
||||||
love.graphics.printf(lick.debugoutput, (love.graphics.getWidth()/2)+50, 0, 400, "right")
|
love.graphics.printf(debugoutput, (love.graphics.getWidth() / 2) + 50, 0, 400, "right")
|
||||||
end
|
end
|
||||||
drawok_old = not drawok
|
drawok_old = not drawok
|
||||||
end
|
end
|
||||||
@ -91,7 +98,8 @@ end
|
|||||||
|
|
||||||
function love.run()
|
function love.run()
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
math.random() math.random()
|
math.random()
|
||||||
|
math.random()
|
||||||
load()
|
load()
|
||||||
|
|
||||||
local dt = 0
|
local dt = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user