Comparison

util/debug.lua @ 4525:e00b4ec5fca4

util.debug: Move boundary markers to top of relevant sections of the stack trace (easier to follow)
author Matthew Wild <mwild1@gmail.com>
date Thu, 22 Mar 2012 16:51:39 +0000
parent 4524:816c319a09d8
child 4684:dc70c4ffb66d
comparison
equal deleted inserted replaced
4524:816c319a09d8 4525:e00b4ec5fca4
111 return ret; 111 return ret;
112 end 112 end
113 113
114 local function build_source_boundary_marker(last_source_desc) 114 local function build_source_boundary_marker(last_source_desc)
115 local padding = string.rep("-", math.floor(((optimal_line_length - 6) - #last_source_desc)/2)); 115 local padding = string.rep("-", math.floor(((optimal_line_length - 6) - #last_source_desc)/2));
116 return getstring(styles.boundary_padding, "^"..padding).." "..getstring(styles.filename, last_source_desc).." "..getstring(styles.boundary_padding, padding..(#last_source_desc%2==0 and "-^" or "^ ")); 116 return getstring(styles.boundary_padding, "v"..padding).." "..getstring(styles.filename, last_source_desc).." "..getstring(styles.boundary_padding, padding..(#last_source_desc%2==0 and "-v" or "v "));
117 end 117 end
118 118
119 function debug._traceback(thread, message, level) 119 function debug._traceback(thread, message, level)
120 if type(thread) ~= "thread" then 120 if type(thread) ~= "thread" then
121 thread, message, level = coroutine.running(), thread, message; 121 thread, message, level = coroutine.running(), thread, message;
156 func_type = func_type.."function "; 156 func_type = func_type.."function ";
157 end 157 end
158 line = "[Lua] "..getstring(styles.location, info.short_src.." line "..info.currentline).." in "..func_type..getstring(styles.funcname, name).." (defined on line "..info.linedefined..")"; 158 line = "[Lua] "..getstring(styles.location, info.short_src.." line "..info.currentline).." in "..func_type..getstring(styles.funcname, name).." (defined on line "..info.linedefined..")";
159 end 159 end
160 if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous 160 if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous
161 if last_source_desc then
162 table.insert(lines, "\t "..build_source_boundary_marker(last_source_desc));
163 end
164 last_source_desc = source_desc; 161 last_source_desc = source_desc;
162 table.insert(lines, "\t "..build_source_boundary_marker(last_source_desc));
165 end 163 end
166 nlevel = nlevel-1; 164 nlevel = nlevel-1;
167 table.insert(lines, "\t"..(nlevel==0 and ">" or " ")..getstring(styles.level_num, "("..nlevel..") ")..line); 165 table.insert(lines, "\t"..(nlevel==0 and ">" or " ")..getstring(styles.level_num, "("..nlevel..") ")..line);
168 local npadding = (" "):rep(#tostring(nlevel)); 166 local npadding = (" "):rep(#tostring(nlevel));
169 local locals_str = string_from_var_table(level.locals, optimal_line_length, "\t "..npadding); 167 local locals_str = string_from_var_table(level.locals, optimal_line_length, "\t "..npadding);
174 if upvalues_str then 172 if upvalues_str then
175 table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str); 173 table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str);
176 end 174 end
177 end 175 end
178 176
179 table.insert(lines, "\t "..build_source_boundary_marker(last_source_desc)); 177 -- table.insert(lines, "\t "..build_source_boundary_marker(last_source_desc));
180 178
181 return message.."stack traceback:\n"..table.concat(lines, "\n"); 179 return message.."stack traceback:\n"..table.concat(lines, "\n");
182 end 180 end