+ -- I tend to read code from files myself (say using love.filesystem calls)
+ -- rather than offload that to load().
+ -- Functions compiled in this manner have ugly filenames of the form [string "filename"]
+ -- This function cleans out this cruft from error callstacks.
+ -- It also strips out the numeric prefixes we introduce in filenames.
+ function cleaned_up_callstack(callstack)
+ local frames = {}
+ for frame in string.gmatch(callstack, '[^\n]+\n*') do
+ table.insert(frames, cleaned_up_frame(frame))
+ end
+ -- the initial "stack traceback:" line was unindented and remains so
+ return table.concat(frames, '\n\t')
+ end
+
+ function cleaned_up_frame(frame)
+ local line = frame:gsub('^%s*(.-)\n?$', '%1')
+ local filename, rest = line:match('([^:]*):(.*)')
+ return cleaned_up_filename(filename)..':'..rest
+ end
+
+ function cleaned_up_filename(filename)
+ -- pass through frames that don't match this format
+ -- this includes the initial line "stack traceback:"
+ local core_filename = filename:match('^%[string "(.*)"%]$')
+ if core_filename == nil then return filename end
+ -- strip out the numeric prefixes we introduce in filenames
+ local _, core_filename2 = core_filename:match('^(%d+)-(.+)')
+ return core_filename2 or core_filename
+ end
+