Merge text0
This commit is contained in:
commit
e3c8121381
|
@ -8,7 +8,9 @@ Initializing settings:
|
|||
- from defaults
|
||||
- `default_map` absent/present
|
||||
|
||||
- run with an unsupported version. Error message pops up and waits for a key. The app attempts to continue, and doesn't receive the key.
|
||||
- run with an untested version. Error message pops up and waits for a key. The app attempts to continue, and doesn't receive the key.
|
||||
- run with a LÖVE v12 release candidate. No errors; it is a supported version. All tests pass.
|
||||
- create a couple of spuriously failing tests. Run with an untested version. Error message includes message about untested version.
|
||||
|
||||
Code loading:
|
||||
* run love with directory; text editor runs
|
||||
|
|
15
app.lua
15
app.lua
|
@ -12,6 +12,7 @@ local Keys_down = {}
|
|||
-- and a source editor, while giving each the illusion of complete
|
||||
-- control.
|
||||
function love.run()
|
||||
Version, Major_version = App.love_version()
|
||||
App.snapshot_love()
|
||||
live.load()
|
||||
-- have LÖVE delegate all handlers to App if they exist
|
||||
|
@ -138,13 +139,17 @@ function love.run()
|
|||
App.run_tests(record_error)
|
||||
-- example handler
|
||||
if #Test_errors > 0 then
|
||||
print('tests failed; mode error')
|
||||
Mode = 'error'
|
||||
Redo_initialization = true
|
||||
Error_message = 'There were test failures:\n\n'..table.concat(Test_errors, '\n')
|
||||
Error_message = ''
|
||||
if Warning_before_tests then
|
||||
Error_message = Warning_before_tests..'\n\n'
|
||||
end
|
||||
Error_message = Error_message .. 'There were test failures:\n\n'..table.concat(Test_errors, '\n')
|
||||
live.send_run_time_error_to_driver(Error_message)
|
||||
end
|
||||
|
||||
App.version_check()
|
||||
App.initialize_globals()
|
||||
xpcall(function() App.initialize(love.arg.parseGameArguments(arg), arg) end, live.handle_initialization_error)
|
||||
|
||||
|
@ -195,6 +200,12 @@ end
|
|||
|
||||
App = {}
|
||||
|
||||
function App.love_version()
|
||||
local major_version, minor_version = love.getVersion()
|
||||
local version = major_version..'.'..minor_version
|
||||
return version, major_version
|
||||
end
|
||||
|
||||
-- save/restore various framework globals we care about -- only on very first load
|
||||
function App.snapshot_love()
|
||||
if Love_snapshot then return end
|
||||
|
|
35
main.lua
35
main.lua
|
@ -12,26 +12,12 @@ require 'button'
|
|||
require 'edit'
|
||||
Editor_state = {}
|
||||
|
||||
function App.version_check()
|
||||
-- available modes: run, error
|
||||
Mode = 'run'
|
||||
Error_message = nil
|
||||
Error_count = 0
|
||||
-- we'll reuse error mode on load for an initial version check
|
||||
Supported_versions = {'11.5', '11.4', '11.3', '11.2', '11.1', '11.0', '12.0'} -- put the recommended version first
|
||||
local minor_version
|
||||
Major_version, minor_version = love.getVersion()
|
||||
Version = Major_version..'.'..minor_version
|
||||
if array.find(Supported_versions, Version) == nil then
|
||||
Mode = 'error'
|
||||
Error_message = ("This app doesn't support version %s; please use version %s. Press any key to try it with this version anyway."):format(Version, Supported_versions[1])
|
||||
print(Error_message)
|
||||
-- continue initializing everything; hopefully we won't have errors during initialization
|
||||
end
|
||||
end
|
||||
|
||||
-- called both in tests and real run
|
||||
function App.initialize_globals()
|
||||
Supported_versions = {'11.5', '11.4', '11.3', '11.2', '11.1', '11.0', '12.0'} -- put the recommended version first
|
||||
-- Mode initialized elsewhere. Available modes: run, error
|
||||
Error_count = 0
|
||||
|
||||
-- tests currently mostly clear their own state
|
||||
|
||||
-- blinking cursor
|
||||
|
@ -72,6 +58,19 @@ function App.initialize(arg)
|
|||
jit.off()
|
||||
jit.flush()
|
||||
end
|
||||
|
||||
check_love_version()
|
||||
end
|
||||
|
||||
function check_love_version()
|
||||
-- we'll reuse error mode on load for an initial version check
|
||||
if array.find(Supported_versions, Version) == nil then
|
||||
Mode = 'error'
|
||||
if Error_message == nil then Error_message = '' end
|
||||
Error_message = ("This app hasn't been tested with LÖVE version %s; please use version %s if you run into errors. Press a key to try recovering.\n\n%s"):format(Version, Supported_versions[1], Error_message)
|
||||
print(Error_message)
|
||||
-- continue initializing everything; hopefully we won't have errors during initialization
|
||||
end
|
||||
end
|
||||
|
||||
function print_and_log(s)
|
||||
|
|
|
@ -21,6 +21,9 @@ two categories.
|
|||
* `flags` -- some properties of the app window. See [`flags` in `love.graphics.getMode`](https://love2d.org/wiki/love.window.getMode)
|
||||
for details.
|
||||
|
||||
* `Version` -- the running version of LÖVE as a string, e.g. '11.4'.
|
||||
* `Major_version` -- just the part before the period as an int, e.g. 11.
|
||||
|
||||
## Functions you can implement that will get automatically called
|
||||
|
||||
* `on.initialize(arg)` -- called when app starts up. Provides in `arg` an
|
||||
|
|
Loading…
Reference in New Issue