diff --git a/utils/debug.lua b/utils/debug.lua index c8b9e77a..f56b1349 100644 --- a/utils/debug.lua +++ b/utils/debug.lua @@ -1,5 +1,7 @@ --- dependencies +-- localised functions local format = string.format +local match = string.match +local gsub = string.gsub local serialize = serpent.line local debug_getupvalue = debug.getupvalue @@ -16,27 +18,50 @@ local function increment() return next end ---- Takes the output from debug.getinfo and strips the function and full source names +--- Takes the table output from debug.getinfo and pretties it local function cleanup_debug(debug_table) - return format('caller details: name: %s file: %s, line number: %s', debug_table.name, debug_table.short_src, debug_table.currentline) + local short_src = match(debug_table.source, '/[^/]*/[^/]*$') + -- require will not return a valid string so short_src may be nil here + if short_src then + short_src = gsub(short_src, '%.lua', '') + end + + return format('[function: %s file: %s line number: %s]', debug_table.name, short_src, debug_table.currentline) end ---Shows the given message if debug is enabled. Uses serpent to print non scalars. -- @param message