# HG changeset patch # User Matthew Wild # Date 1332428977 0 # Node ID 4c7495f7f543fd5fa86994bc11497eef1b949c3d # Parent 2d85ac26799c5defd7d9688370715e093dde5400 util.debug: Add markers in the output when crossing source file boundaries diff -r 2d85ac26799c -r 4c7495f7f543 util/debug.lua --- a/util/debug.lua Thu Mar 22 15:08:21 2012 +0000 +++ b/util/debug.lua Thu Mar 22 15:09:37 2012 +0000 @@ -114,11 +114,14 @@ local levels = get_traceback_table(thread, level+2); + local last_source_desc; + local lines = {}; for nlevel, level in ipairs(levels) do local info = level.info; local line = "..."; local func_type = info.namewhat.." "; + local source_desc = (info.short_src == "[C]" and "C code") or info.short_src or "Unknown"; if func_type == " " then func_type = ""; end; if info.short_src == "[C]" then line = "[ C ] "..func_type.."C function "..(info.name and ("%q"):format(info.name) or "(unknown name)") @@ -134,6 +137,13 @@ end line = "[Lua] "..info.short_src.." line "..info.currentline.." in "..func_type..name.." defined on line "..info.linedefined; end + if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous + if last_source_desc then + local padding = string.rep("-", math.floor(((65 - 6) - #last_source_desc)/2)); + table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ ")); + end + last_source_desc = source_desc; + end nlevel = nlevel-1; table.insert(lines, "\t"..(nlevel==0 and ">" or " ").."("..nlevel..") "..line); local npadding = (" "):rep(#tostring(nlevel)); @@ -146,5 +156,9 @@ table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str); end end + + local padding = string.rep("-", math.floor(((65 - 6) - #last_source_desc) / 2)); + table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ ")); + return message.."stack traceback:\n"..table.concat(lines, "\n"); end