run script on startup; new button to switch to source editor
This commit is contained in:
parent
a2c099a0c9
commit
694a148043
|
@ -19,4 +19,5 @@ on.initialize = function()
|
||||||
Current_pane_index = 1
|
Current_pane_index = 1
|
||||||
Current_pane = Panes[Current_pane_index]
|
Current_pane = Panes[Current_pane_index]
|
||||||
end
|
end
|
||||||
|
run_app()
|
||||||
end
|
end
|
|
@ -2,26 +2,7 @@ run_button = function(x, y)
|
||||||
styled_button('run', x,y,
|
styled_button('run', x,y,
|
||||||
function()
|
function()
|
||||||
Show_menu = nil
|
Show_menu = nil
|
||||||
-- ## run: initialize
|
run_app()
|
||||||
clear_handlers()
|
|
||||||
local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')
|
|
||||||
edit.clear(Current_pane.output_editor_state)
|
|
||||||
print = print_to_output
|
|
||||||
-- ## run
|
|
||||||
local error = eval_all()
|
|
||||||
-- ## run: save some stuff, clean up the rest
|
|
||||||
if error == nil then
|
|
||||||
Show_code = nil
|
|
||||||
else
|
|
||||||
print = Real_print
|
|
||||||
clear_handlers()
|
|
||||||
-- could be either output or error
|
|
||||||
table.insert(Current_pane.output_editor_state.lines, {data=tostring(error)})
|
|
||||||
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)
|
|
||||||
end)
|
end)
|
||||||
local w = App.width('run')+10
|
local w = App.width('run')+10
|
||||||
return x+w+10, y
|
return x+w+10, y
|
||||||
|
|
|
@ -5,6 +5,5 @@ send_errors_to_output = function(err)
|
||||||
Current_pane.output_editor_state.cursor1 = {line=#Current_pane.output_editor_state.lines, pos=1}
|
Current_pane.output_editor_state.cursor1 = {line=#Current_pane.output_editor_state.lines, pos=1}
|
||||||
Text.redraw_all(Current_pane.output_editor_state)
|
Text.redraw_all(Current_pane.output_editor_state)
|
||||||
Text.insert_text(Current_pane.output_editor_state, error_with_callstack)
|
Text.insert_text(Current_pane.output_editor_state, error_with_callstack)
|
||||||
clear_handlers()
|
stop_app()
|
||||||
Show_code = true
|
|
||||||
end
|
end
|
|
@ -0,0 +1,21 @@
|
||||||
|
run_app = function()
|
||||||
|
-- ## run: initialize
|
||||||
|
clear_handlers()
|
||||||
|
edit.clear(Current_pane.output_editor_state)
|
||||||
|
print = print_to_output
|
||||||
|
-- ## run
|
||||||
|
local error = eval_all()
|
||||||
|
-- ## run: save some stuff, clean up the rest
|
||||||
|
if error == nil then
|
||||||
|
Show_code = nil
|
||||||
|
else
|
||||||
|
print = Real_print
|
||||||
|
clear_handlers()
|
||||||
|
-- could be either output or error
|
||||||
|
table.insert(Current_pane.output_editor_state.lines, {data=tostring(error)})
|
||||||
|
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)
|
||||||
|
end
|
|
@ -0,0 +1,4 @@
|
||||||
|
stop_app = function()
|
||||||
|
clear_handlers()
|
||||||
|
Show_code = true
|
||||||
|
end
|
|
@ -6,6 +6,13 @@
|
||||||
-- adjust zoom based on two-finger touch (touchscreen only)
|
-- adjust zoom based on two-finger touch (touchscreen only)
|
||||||
|
|
||||||
function car.draw()
|
function car.draw()
|
||||||
|
color(0, 0.6,0.6)
|
||||||
|
line(Safe_width-120, 0, Safe_width-120, 40)
|
||||||
|
g.setFont(Font)
|
||||||
|
local s = App.width('exit')
|
||||||
|
line(Safe_width-120, 40, Safe_width-s-20, 40)
|
||||||
|
line(Safe_width-s-20, 40, Safe_width-s-20, 110)
|
||||||
|
line(Safe_width-s-20, 110, Safe_width+100, 110)
|
||||||
for _,w in ipairs(widgets) do w.draw() end
|
for _,w in ipairs(widgets) do w.draw() end
|
||||||
draw_hud()
|
draw_hud()
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,32 @@
|
||||||
widgets = {}
|
widgets = {}
|
||||||
|
|
||||||
-- button to invoke add_editor
|
-- button to add a text box
|
||||||
table.insert(widgets, {
|
table.insert(widgets, {
|
||||||
draw = function()
|
draw = function()
|
||||||
color(0, 0.6,0.6)
|
color(0, 0.6,0.6)
|
||||||
rect('line', Safe_width-65, Menu_bottom+5, 30,30, 5)
|
rect('line', Safe_width-115, 5, 30,30, 5)
|
||||||
line(Safe_width-60, Menu_bottom+20, Safe_width-40, Menu_bottom+20)
|
line(Safe_width-110, 20, Safe_width-90, 20)
|
||||||
line(Safe_width-50, Menu_bottom+10, Safe_width-50, Menu_bottom+30)
|
line(Safe_width-100, 10, Safe_width-100, 30)
|
||||||
end,
|
end,
|
||||||
ispress = function(x2,y2)
|
ispress = function(x2,y2)
|
||||||
return x2 >= Safe_width-65 and y2 <= Menu_bottom+35
|
return x2 >= Safe_width-120 and x2 <= Safe_width-85 and y2 <= 40
|
||||||
end,
|
end,
|
||||||
press = add_editor,
|
press = add_editor,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- button to stop the app and return to the source editor
|
||||||
|
table.insert(widgets, {
|
||||||
|
draw = function()
|
||||||
|
color(0, 0.6,0.6)
|
||||||
|
g.setFont(Font)
|
||||||
|
local s = App.width('exit')
|
||||||
|
rect('line', Safe_width-s-15, 75, s+10,30, 5)
|
||||||
|
g.print('exit', Safe_width-s-10, 80)
|
||||||
|
end,
|
||||||
|
ispress = function(x2,y2)
|
||||||
|
g.setFont(Font)
|
||||||
|
local s = App.width('exit')
|
||||||
|
return x2 >= Safe_width-s-15 and y2 >= 75 and y2 <= 105
|
||||||
|
end,
|
||||||
|
press = stop_app,
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue