about summary refs log tree commit diff stats
path: root/app.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-09-03 14:13:22 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-09-03 14:13:22 -0700
commite1c5a42f311fdafd88506726bbe480f3fcc2d1a3 (patch)
tree6628729cc55947d0bd5d306704e88b57680c3514 /app.lua
parent9c72ff1bb4fc1ba08acfb0324079da6fe49f3a4a (diff)
downloadlines.love-e1c5a42f311fdafd88506726bbe480f3fcc2d1a3.tar.gz
editing source code from within the app
integrated from pong.love via text.love:
  https://merveilles.town/@akkartik/108933336531898243
Diffstat (limited to 'app.lua')
-rw-r--r--app.lua29
1 files changed, 23 insertions, 6 deletions
diff --git a/app.lua b/app.lua
index cac1303..2135fb0 100644
--- a/app.lua
+++ b/app.lua
@@ -1,4 +1,4 @@
--- main entrypoint for LÖVE
+-- love.run: main entrypoint function for LÖVE
 --
 -- Most apps can just use the default, but we need to override it to
 -- install a test harness.
@@ -11,13 +11,10 @@
 --
 -- Scroll below this function for more details.
 function love.run()
+  App.snapshot_love()
   -- Tests always run at the start.
-  App.run_tests()
-
+  App.run_tests_and_initialize()
 --?   print('==')
-  App.disable_tests()
-  App.initialize_globals()
-  App.initialize(love.arg.parseGameArguments(arg), arg)
 
   love.timer.step()
   local dt = 0
@@ -123,6 +120,26 @@ end
 
 App = {screen={}}
 
+-- save/restore various framework globals we care about -- only on very first load
+function App.snapshot_love()
+  if Love_snapshot then return end
+  Love_snapshot = {}
+  -- save the entire initial font; it doesn't seem reliably recreated using newFont
+  Love_snapshot.initial_font = love.graphics.getFont()
+end
+
+function App.undo_initialize()
+  love.graphics.setFont(Love_snapshot.initial_font)
+end
+
+function App.run_tests_and_initialize()
+  App.load()
+  App.run_tests()
+  App.disable_tests()
+  App.initialize_globals()
+  App.initialize(love.arg.parseGameArguments(arg), arg)
+end
+
 function App.initialize_for_test()
   App.screen.init({width=100, height=50})
   App.screen.contents = {}  -- clear screen