Added support for files loaded through LÖVE, and added error-handling if no file can be found.
This commit is contained in:
parent
e994147512
commit
1b0b6d14d4
|
@ -148,19 +148,38 @@ end
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function get_module_filetext (module_filepath)
|
||||
assert(type(module_filepath) == 'string')
|
||||
|
||||
-- Just attempt standard file open
|
||||
local filehandle = io.open(module_filepath, 'r')
|
||||
if filehandle then
|
||||
filetext = filehandle:read '*all'
|
||||
filehandle:close()
|
||||
return filetext
|
||||
end
|
||||
|
||||
-- What about LÖVE?
|
||||
local filetext = love and love.filesystem and love.filesystem.read(module_filepath) or nil
|
||||
if filetext then return filetext end
|
||||
|
||||
-- I give up...
|
||||
return nil
|
||||
end
|
||||
|
||||
local function get_assert_body_text (call_info)
|
||||
if call_info.what == 'Lua' or call_info.what == 'main' then
|
||||
-- Find filetext
|
||||
local filetext = nil
|
||||
if call_info.source:find '^@' then
|
||||
local filehandle = io.open(call_info.short_src, 'r')
|
||||
filetext = filehandle:read '*all'
|
||||
filehandle:close()
|
||||
filetext = get_module_filetext(call_info.short_src)
|
||||
elseif call_info.short_src:find '^%[string' then
|
||||
filetext = call_info.source
|
||||
else
|
||||
error 'Not implemented yet!'
|
||||
end
|
||||
-- If cannot find
|
||||
if not filetext then return nil end
|
||||
-- Get lines
|
||||
local filetext = filetext .. '\n'
|
||||
local lines_after, line_i = {}, 0
|
||||
|
@ -264,6 +283,9 @@ local function determine_error_message (call_info, msg, condition)
|
|||
-- Get assert body.
|
||||
local body_text = get_assert_body_text(call_info)
|
||||
|
||||
-- If we couldn't find the body text, we give up.
|
||||
if not body_text then return end
|
||||
|
||||
-- Simplest formatting.
|
||||
-- No analysis of the assert-body, just report that it failed,
|
||||
-- along with it's body.
|
||||
|
|
Loading…
Reference in New Issue
Block a user