sokoban.love/0051-run_button

37 lines
1.3 KiB
Plaintext

run_button = function(x)
local w = App.width('Run')+10
button(Global_state, 'run', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
icon = function(p)
App.color(Normal_color)
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
love.graphics.print('Run', p.x+5,p.y+2)
end,
onpress1 = function()
-- ## run: initialize
local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')
Current_pane.canvas = love.graphics.newCanvas()
love.graphics.setCanvas(Current_pane.canvas)
love.graphics.push('all')
-- love.graphics.setBackgroundColor(Background_color.r, Background_color.g, Background_color.b)
Current_pane.output_editor_state.lines = {}
Text.redraw_all(Current_pane.output_editor_state)
local real_print = print
print = print_to_output
-- ## run
local status, result = live.eval(buf)
-- ## run: save some stuff, clean up the rest
print = real_print
if result then
-- could be either output or error
table.insert(Current_pane.output_editor_state.lines, {data=tostring(result)})
end
if #Current_pane.output_editor_state.lines == 0 then
table.insert(Current_pane.output_editor_state.lines, {data=''})
end
Text.redraw_all(Current_pane.output_editor_state)
love.graphics.pop()
love.graphics.setCanvas()
end,
})
return x+w+10
end