about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app.lua21
1 files changed, 18 insertions, 3 deletions
diff --git a/app.lua b/app.lua
index da43889..b520077 100644
--- a/app.lua
+++ b/app.lua
@@ -2,6 +2,7 @@
 --
 -- Most apps can just use the default shown in https://love2d.org/wiki/love.run,
 -- but we need to override it to:
+--   * recover from errors (by switching to the source editor)
 --   * run all tests (functions starting with 'test_') on startup, and
 --   * save some state that makes it possible to switch between the main app
 --     and a source editor, while giving each the illusion of complete
@@ -24,22 +25,36 @@ function love.run()
             return a or 0
           end
         end
-        love.handlers[name](a,b,c,d,e,f)
+        xpcall(function() love.handlers[name](a,b,c,d,e,f) end, handle_error)
       end
     end
 
     dt = love.timer.step()
-    App.update(dt)
+    xpcall(function() App.update(dt) end, handle_error)
 
     love.graphics.origin()
     love.graphics.clear(love.graphics.getBackgroundColor())
-    App.draw()
+    xpcall(App.draw, handle_error)
     love.graphics.present()
 
     love.timer.sleep(0.001)
   end
 end
 
+function handle_error(err)
+  Error_message = debug.traceback('Error: ' .. tostring(err), --[[stack frame]]2):gsub('\n[^\n]+$', '')
+  print(Error_message)
+  if Current_app == 'run' then
+    Settings.current_app = 'source'
+    love.filesystem.write('config', json.encode(Settings))
+    load_file_from_source_or_save_directory('main.lua')
+    App.undo_initialize()
+    App.run_tests_and_initialize()
+  else
+    love.event.quit()
+  end
+end
+
 -- The rest of this file wraps around various LÖVE primitives to support
 -- automated tests. Often tests will run with a fake version of a primitive
 -- that redirects to the real love.* version once we're done with tests.
om> 2021-01-24 19:38:10 -0800 committer Kartik Agaram <vc@akkartik.com> 2021-01-24 20:16:27 -0800 7559 - reorganize sectors built in raw hex' href='/akkartik/mu/commit/baremetal/103grapheme.subx?h=main&id=3844651e49258a400ed81273f7cd620a14264386'>3844651e ^
6ce43fce ^
dbf434f0 ^
6e36ce06 ^
dbf434f0 ^

6e36ce06 ^
dbf434f0 ^
7f8770ae ^

dbf434f0 ^
7f8770ae ^

dbf434f0 ^
6ce43fce ^
dbf434f0 ^
7f8770ae ^
dbf434f0 ^
6e36ce06 ^
dbf434f0 ^
7f8770ae ^



dbf434f0 ^
7f8770ae ^



7363c6df ^
7f8770ae ^

6e36ce06 ^
6ce43fce ^
7f8770ae ^
7363c6df ^

6ce43fce ^
7f8770ae ^













6ce43fce ^
7f8770ae ^









44131682 ^
6e36ce06 ^
44131682 ^



121a9eba ^

6ce43fce ^
44131682 ^




63be7b7d ^
422ebaf8 ^




121a9eba ^
6e36ce06 ^
121a9eba ^
6e36ce06 ^
121a9eba ^
6ce43fce ^
422ebaf8 ^






63be7b7d ^




f0ef1ca2 ^
63be7b7d ^


















44131682 ^

121a9eba ^
63be7b7d ^










121a9eba ^
63be7b7d ^

121a9eba ^
44131682 ^
121a9eba ^
44131682 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173