From e1c5a42f311fdafd88506726bbe480f3fcc2d1a3 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 3 Sep 2022 14:13:22 -0700 Subject: editing source code from within the app integrated from pong.love via text.love: https://merveilles.town/@akkartik/108933336531898243 --- app.lua | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'app.lua') 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 -- cgit 1.4.1-2-gfad0