sokoban.love/0051-run_button

31 lines
1.0 KiB
Plaintext
Raw Normal View History

run_button = function(x, y)
2023-11-26 07:03:20 +00:00
styled_button('run', x,y,
function()
2023-12-05 06:09:47 +00:00
Show_menu = nil
-- ## run: initialize
clear_handlers()
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(1,1,1)
edit.clear(Current_pane.output_editor_state)
print = print_to_output
-- ## run
local status, result = live.eval(buf, 'editor')
-- ## run: save some stuff, clean up the rest
2023-12-17 21:30:17 +00:00
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()
2023-11-26 07:03:20 +00:00
end)
local w = App.width('run')+10
return x+w+10, y
2023-12-17 21:30:17 +00:00
end