implement 'Run' button

Error flow is still klunky. We'll need to implement the output region
for that.
This commit is contained in:
Kartik K. Agaram 2023-11-18 19:42:00 -08:00
parent 8958100df1
commit e53245e62d
5 changed files with 29 additions and 0 deletions

View File

@ -1,5 +1,7 @@
on.draw = function()
Editor_state.button_handlers = {}
draw_canvas()
--if Canvas then return end
draw_editor_border()
-- love.graphics.rectangle('line', 100-5-Line_number_padding,100-5, 300+Line_number_padding+10, 200+10, 5,5)
edit.draw(Editor_state)

View File

@ -10,6 +10,18 @@ draw_menu = function()
end,
onpress1 = function()
print('run')
local buf = table.concat(map(Editor_state.lines, function(line) return line.data end), '\n')
Canvas = love.graphics.newCanvas()
love.graphics.setCanvas(Canvas)
love.graphics.push('all')
love.graphics.setBackgroundColor(1,1,1)
love.graphics.setColor(0,0,0)
local status, result = live.eval(buf)
if not status then
print(result)
end
love.graphics.pop()
love.graphics.setCanvas()
end,
})
-- settings button on right

1
0041-Canvas Normal file
View File

@ -0,0 +1 @@
Canvas = nil

7
0042-draw_canvas Normal file
View File

@ -0,0 +1,7 @@
draw_canvas = function()
if Canvas == nil then return end
love.graphics.setBlendMode('alpha', 'premultiplied')
love.graphics.setColor(1,1,1,1)
love.graphics.draw(Canvas, 0,0)
love.graphics.setBlendMode('alpha')
end

7
0043-map Normal file
View File

@ -0,0 +1,7 @@
map = function(arr, f)
local result = {}
for _, x in ipairs(arr) do
table.insert(result, f(x))
end
return result
end