confirm that we have access to all of the love API

love.graphics.line(1, 1, 500, 500)

However, we're now no longer printing results or errors. Time now to
design the data model. When do we (re)evaluate code. When do we display
results. Where do errors go.
This commit is contained in:
Kartik K. Agaram 2022-05-02 08:36:56 -07:00
parent 4ad1cc4b54
commit 3019442c02
1 changed files with 14 additions and 4 deletions

View File

@ -3,6 +3,7 @@ local utf8 = require 'utf8'
lines = {} lines = {}
width, height, flags = 0, 0, nil width, height, flags = 0, 0, nil
exec_payload = nil
function love.load() function love.load()
table.insert(lines, '') table.insert(lines, '')
@ -24,6 +25,10 @@ function love.draw()
end end
-- cursor -- cursor
love.graphics.print('_', 12+text:getWidth(), #lines*15) love.graphics.print('_', 12+text:getWidth(), #lines*15)
if exec_payload then
call_gather(exec_payload)
end
end end
function love.update(dt) function love.update(dt)
@ -47,8 +52,9 @@ function keychord_pressed(chord)
end end
end end
elseif chord == 'C-r' then elseif chord == 'C-r' then
lines[#lines+1] = eval(lines[#lines])[1] eval(lines[#lines])
lines[#lines+1] = '' --? lines[#lines+1] = eval(lines[#lines])[1]
--? lines[#lines+1] = ''
end end
end end
@ -64,11 +70,15 @@ end
function eval(buf) function eval(buf)
local f = load('return '..buf, 'REPL') local f = load('return '..buf, 'REPL')
if f then if f then
return call_gather(f) exec_payload = f
return
--? return call_gather(f)
end end
local f, err = load(buf, 'REPL') local f, err = load(buf, 'REPL')
if f then if f then
return call_gather(f) exec_payload = f
return
--? return call_gather(f)
else else
return {err} return {err}
end end