mirror of
https://github.com/usysrc/LICK.git
synced 2024-11-16 09:34:22 +00:00
Merge pull request #1 from davidgomes/patch-1
Fixed indentation from tabs to spaces, and cleaned up the code a bit.
This commit is contained in:
commit
fb9319c889
187
lick.lua
187
lick.lua
@ -2,8 +2,6 @@
|
|||||||
--
|
--
|
||||||
-- simple LIVECODING environment with löve, overwrites love.run, pressing all errors to the terminal/console
|
-- simple LIVECODING environment with löve, overwrites love.run, pressing all errors to the terminal/console
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local lick = {}
|
local lick = {}
|
||||||
lick.file = "main.lua"
|
lick.file = "main.lua"
|
||||||
lick.debug = false
|
lick.debug = false
|
||||||
@ -14,119 +12,118 @@ lick.sleepTime = love.graphics.newCanvas and 0.001 or 1
|
|||||||
local last_modified = 0
|
local last_modified = 0
|
||||||
|
|
||||||
local function handle(err)
|
local function handle(err)
|
||||||
return "ERROR: " .. err
|
return "ERROR: " .. err
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Initialization
|
-- Initialization
|
||||||
local function load()
|
local function load()
|
||||||
last_modified = 0
|
last_modified = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update(dt)
|
local function update(dt)
|
||||||
if love.filesystem.exists(lick.file) and last_modified < love.filesystem.getLastModified(lick.file) then
|
if love.filesystem.exists(lick.file) and last_modified < love.filesystem.getLastModified(lick.file) then
|
||||||
last_modified = love.filesystem.getLastModified(lick.file)
|
last_modified = love.filesystem.getLastModified(lick.file)
|
||||||
success, chunk = pcall(love.filesystem.load, lick.file)
|
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"
|
lick.debugoutput = chunk .. "\n"
|
||||||
end
|
end
|
||||||
ok,err = xpcall(chunk, handle)
|
ok,err = xpcall(chunk, handle)
|
||||||
if not ok then
|
|
||||||
print(tostring(err))
|
if not ok then
|
||||||
if lick.debugoutput then
|
print(tostring(err))
|
||||||
lick.debugoutput = (lick.debugoutput .."ERROR: ".. err .. "\n" )
|
if lick.debugoutput then
|
||||||
else lick.debugoutput = err .. "\n" end
|
lick.debugoutput = (lick.debugoutput .."ERROR: ".. err .. "\n" )
|
||||||
end
|
else lick.debugoutput = err .. "\n" end
|
||||||
if ok then
|
else
|
||||||
print("CHUNK LOADED\n")
|
print("CHUNK LOADED\n")
|
||||||
lick.debugoutput = nil
|
lick.debugoutput = nil
|
||||||
end
|
end
|
||||||
if lick.reset then
|
|
||||||
loadok, err = xpcall(love.load, handle)
|
if lick.reset then
|
||||||
if not loadok and not loadok_old then
|
loadok, err = xpcall(love.load, handle)
|
||||||
print("ERROR: "..tostring(err))
|
if not loadok and not loadok_old then
|
||||||
if lick.debugoutput then
|
print("ERROR: "..tostring(err))
|
||||||
lick.debugoutput = (lick.debugoutput .."ERROR: ".. err .. "\n" )
|
if lick.debugoutput then
|
||||||
else
|
lick.debugoutput = (lick.debugoutput .."ERROR: ".. err .. "\n" )
|
||||||
lick.debugoutput = err .. "\n"
|
else
|
||||||
end
|
lick.debugoutput = err .. "\n"
|
||||||
loadok_old = not loadok
|
end
|
||||||
end
|
loadok_old = not loadok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
updateok, err = pcall(love.update,dt)
|
|
||||||
if not updateok and not updateok_old then
|
updateok, err = pcall(love.update,dt)
|
||||||
print("ERROR: "..tostring(err))
|
if not updateok and not updateok_old then
|
||||||
if lick.debugoutput then
|
print("ERROR: "..tostring(err))
|
||||||
lick.debugoutput = (lick.debugoutput .."ERROR: ".. err .. "\n" )
|
if lick.debugoutput then
|
||||||
else lick.debugoutput = err .. "\n" end
|
lick.debugoutput = (lick.debugoutput .."ERROR: ".. err .. "\n" )
|
||||||
end
|
else lick.debugoutput = err .. "\n" end
|
||||||
|
end
|
||||||
updateok_old = not updateok
|
|
||||||
|
updateok_old = not updateok
|
||||||
end
|
end
|
||||||
|
|
||||||
local function draw()
|
local function draw()
|
||||||
drawok, err = xpcall(love.draw, handle)
|
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 lick.debugoutput then
|
||||||
lick.debugoutput = (lick.debugoutput .. err .. "\n" )
|
lick.debugoutput = (lick.debugoutput .. err .. "\n" )
|
||||||
else lick.debugoutput = err .. "\n" end
|
else lick.debugoutput = err .. "\n" end
|
||||||
end
|
end
|
||||||
if lick.debug and lick.debugoutput then
|
|
||||||
love.graphics.setColor(255,255,255,120)
|
if lick.debug and lick.debugoutput then
|
||||||
love.graphics.printf(lick.debugoutput, (love.graphics.getWidth()/2)+50, 0, 400, "right")
|
love.graphics.setColor(255,255,255,120)
|
||||||
end
|
love.graphics.printf(lick.debugoutput, (love.graphics.getWidth()/2)+50, 0, 400, "right")
|
||||||
drawok_old = not drawok
|
end
|
||||||
|
drawok_old = not drawok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function love.run()
|
function love.run()
|
||||||
|
math.randomseed(os.time())
|
||||||
|
math.random() math.random()
|
||||||
|
load()
|
||||||
|
|
||||||
math.randomseed(os.time())
|
local dt = 0
|
||||||
math.random() math.random()
|
|
||||||
load()
|
|
||||||
|
|
||||||
|
|
||||||
local dt = 0
|
-- Main loop time.
|
||||||
|
while true do
|
||||||
-- Main loop time.
|
-- Process events.
|
||||||
while true do
|
if love.event then
|
||||||
-- Process events.
|
love.event.pump()
|
||||||
if love.event then
|
for e,a,b,c,d in love.event.poll() do
|
||||||
love.event.pump()
|
if e == "quit" then
|
||||||
for e,a,b,c,d in love.event.poll() do
|
if not love.quit or not love.quit() then
|
||||||
if e == "quit" then
|
if love.audio then
|
||||||
if not love.quit or not love.quit() then
|
love.audio.stop()
|
||||||
if love.audio then
|
|
||||||
love.audio.stop()
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
love.handlers[e](a,b,c,d)
|
|
||||||
end
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update dt, as we'll be passing it to update
|
love.handlers[e](a,b,c,d)
|
||||||
if love.timer then
|
end
|
||||||
love.timer.step()
|
|
||||||
dt = love.timer.getDelta()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Call update and draw
|
|
||||||
if update then update(dt) end -- will pass 0 if love.timer is disabled
|
|
||||||
if love.graphics then
|
|
||||||
love.graphics.clear()
|
|
||||||
if draw then draw() end
|
|
||||||
end
|
|
||||||
|
|
||||||
if love.timer then love.timer.sleep(0.001) end
|
|
||||||
if love.graphics then love.graphics.present() end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Update dt, as we'll be passing it to update
|
||||||
|
if love.timer then
|
||||||
|
love.timer.step()
|
||||||
|
dt = love.timer.getDelta()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Call update and draw
|
||||||
|
if update then update(dt) end -- will pass 0 if love.timer is disabled
|
||||||
|
if love.graphics then
|
||||||
|
love.graphics.clear()
|
||||||
|
if draw then draw() end
|
||||||
|
end
|
||||||
|
|
||||||
|
if love.timer then love.timer.sleep(0.001) end
|
||||||
|
if love.graphics then love.graphics.present() end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return lick
|
return lick
|
Loading…
Reference in New Issue
Block a user