1
0

Added support for files loaded through LÖVE, and added error-handling if no file can be found.

This commit is contained in:
Jon Michael Aanes 2018-01-26 13:09:53 +01:00
parent e994147512
commit 1b0b6d14d4

View File

@ -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.