send errors from event handlers to output editor
This commit is contained in:
parent
fc3cb96171
commit
2e66d2f0fd
|
@ -8,5 +8,5 @@ on.update = function(dt)
|
|||
elseif Current_pane.output_editor_state.scrollbar_drag then
|
||||
adjust_scrollbar(Current_pane.output_editor_state, App.mouse_y())
|
||||
end
|
||||
if car.update then car.update(dt) end
|
||||
if car.update then call_protected(car.update, dt) end
|
||||
end
|
|
@ -3,7 +3,7 @@ on.draw = function()
|
|||
love.graphics.setBackgroundColor(Background_color.r, Background_color.g, Background_color.b)
|
||||
draw_canvas()
|
||||
App.color(Foreground_color)
|
||||
if car.draw then car.draw() end -- off canvas
|
||||
if car.draw then call_protected(car.draw) end -- off canvas
|
||||
if Show_code then
|
||||
draw_editor_border()
|
||||
edit.draw(Current_pane.editor_state, --[[implicitly use Foreground_color]] nil, --[[hide_cursor]] nil, --[[show_line_numbers]] true)
|
||||
|
|
|
@ -12,7 +12,11 @@ on.keychord_press = function(chord, key)
|
|||
end
|
||||
else
|
||||
-- editors hidden
|
||||
if car.keychord_press then car.keychord_press(chord, key) end
|
||||
if car.keypressed then car.keypressed(key) end
|
||||
if car.keychord_press then
|
||||
call_protected(car.keychord_press, chord, key)
|
||||
end
|
||||
if car.keypressed then
|
||||
call_protected(car.keypressed, key)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,7 +5,11 @@ on.text_input = function(t)
|
|||
end
|
||||
else
|
||||
-- editors hidden
|
||||
if car.text_input then car.text_input(t) end
|
||||
if car.textinput then car.textinput(t) end
|
||||
if car.text_input then
|
||||
call_protected(car.text_input, t)
|
||||
end
|
||||
if car.textinput then
|
||||
call_protected(car.textinput, t)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,7 +5,11 @@ on.key_release = function(key, scancode)
|
|||
end
|
||||
else
|
||||
-- editors hidden
|
||||
if car.key_release then car.key_release(key, scancode) end
|
||||
if car.keyreleased then car.keyreleased(key, scancode) end
|
||||
if car.key_release then
|
||||
call_protected(car.key_release, key, scancode)
|
||||
end
|
||||
if car.keyreleased then
|
||||
call_protected(car.keyreleased, key, scancode)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -16,7 +16,11 @@ on.mouse_release = function(x,y, mouse_button)
|
|||
end
|
||||
else
|
||||
-- editors hidden
|
||||
if car.mouse_release then car.mouse_release(x,y, mouse_button) end
|
||||
if car.mousereleased then car.mousereleased(x,y, mouse_button) end
|
||||
if car.mouse_release then
|
||||
call_protected(car.mouse_release, x,y, mouse_button)
|
||||
end
|
||||
if car.mousereleased then
|
||||
call_protected(car.mousereleased, x,y, mouse_button)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,17 +8,17 @@ run_button = function(x)
|
|||
end,
|
||||
onpress1 = function()
|
||||
-- ## 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)
|
||||
Current_pane.output_editor_state.lines = {}
|
||||
Text.redraw_all(Current_pane.output_editor_state)
|
||||
edit.clear(Current_pane.output_editor_state)
|
||||
local real_print = print
|
||||
print = print_to_output
|
||||
-- ## run
|
||||
local status, result = live.eval(buf)
|
||||
local status, result = live.eval(buf, 'editor')
|
||||
-- ## run: save some stuff, clean up the rest
|
||||
print = real_print
|
||||
if result then
|
||||
|
|
|
@ -3,7 +3,11 @@ on.mouse_wheel_move = function(dx,dy)
|
|||
-- nothing yet
|
||||
else
|
||||
-- editors hidden
|
||||
if car.mouse_wheel_move then car.mouse_wheel_move(dx,dy) end
|
||||
if car.wheelmoved then car.wheelmoved(dx,dy) end
|
||||
if car.mouse_wheel_move then
|
||||
call_protected(car.mouse_wheel_move, dx,dy)
|
||||
end
|
||||
if car.wheelmoved then
|
||||
call_protected(car.wheelmoved, dx,dy)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
send_errors_to_output = function(err)
|
||||
local callstack = debug.traceback('', 3)
|
||||
local error_with_callstack = cleaned_up_frame(tostring(err))..'\n'..cleaned_up_callstack(callstack)
|
||||
Text.insert_text(Current_pane.output_editor_state, error_with_callstack)
|
||||
Text.redraw_all(Current_pane.output_editor_state)
|
||||
clear_handlers()
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
call_protected = function(f, ...)
|
||||
local args = {...}
|
||||
xpcall(
|
||||
function()
|
||||
f(unpack(args))
|
||||
end,
|
||||
send_errors_to_output)
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
clear_handlers = function()
|
||||
for k in pairs(car) do
|
||||
car[k] = nil
|
||||
end
|
||||
end
|
7
edit.lua
7
edit.lua
|
@ -394,6 +394,13 @@ function Text.insert_text(State, d)
|
|||
end
|
||||
end
|
||||
|
||||
function edit.clear(State)
|
||||
State.lines = {{data=''}}
|
||||
Text.redraw_all(State)
|
||||
State.cursor1 = {line=1, pos=1}
|
||||
State.screen_top1 = {line=1, pos=1}
|
||||
end
|
||||
|
||||
function edit.key_release(State, key, scancode)
|
||||
end
|
||||
|
||||
|
|
|
@ -196,6 +196,8 @@ early warning if you break something.
|
|||
`x=right`. Wraps long lines at word boundaries where possible, or in the
|
||||
middle of words (no hyphenation yet) when it must.
|
||||
|
||||
* `edit.clear_state(state)` -- empties the editor of any text it may contain.
|
||||
|
||||
* `state.lines = load_array(lines)` -- loads the editor state with the array
|
||||
of `lines`
|
||||
|
||||
|
|
Loading…
Reference in New Issue