Mercurial > prosody-hg
comparison util/debug.lua @ 4522:29f75c2af90e
util.debug: Move optimal line length (default 65) into a variable
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 22 Mar 2012 15:10:38 +0000 |
| parents | 4c7495f7f543 |
| children | d733bde93074 |
comparison
equal
deleted
inserted
replaced
| 4521:4c7495f7f543 | 4522:29f75c2af90e |
|---|---|
| 5 password = true; | 5 password = true; |
| 6 passwd = true; | 6 passwd = true; |
| 7 pass = true; | 7 pass = true; |
| 8 pwd = true; | 8 pwd = true; |
| 9 }; | 9 }; |
| 10 local optimal_line_length = 65; | |
| 11 | |
| 10 | 12 |
| 11 local function get_locals_table(level) | 13 local function get_locals_table(level) |
| 12 level = level + 1; -- Skip this function itself | 14 level = level + 1; -- Skip this function itself |
| 13 local locals = {}; | 15 local locals = {}; |
| 14 for local_num = 1, math.huge do | 16 for local_num = 1, math.huge do |
| 137 end | 139 end |
| 138 line = "[Lua] "..info.short_src.." line "..info.currentline.." in "..func_type..name.." defined on line "..info.linedefined; | 140 line = "[Lua] "..info.short_src.." line "..info.currentline.." in "..func_type..name.." defined on line "..info.linedefined; |
| 139 end | 141 end |
| 140 if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous | 142 if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous |
| 141 if last_source_desc then | 143 if last_source_desc then |
| 142 local padding = string.rep("-", math.floor(((65 - 6) - #last_source_desc)/2)); | 144 local padding = string.rep("-", math.floor(((optimal_line_length - 6) - #last_source_desc)/2)); |
| 143 table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ ")); | 145 table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ ")); |
| 144 end | 146 end |
| 145 last_source_desc = source_desc; | 147 last_source_desc = source_desc; |
| 146 end | 148 end |
| 147 nlevel = nlevel-1; | 149 nlevel = nlevel-1; |
| 148 table.insert(lines, "\t"..(nlevel==0 and ">" or " ").."("..nlevel..") "..line); | 150 table.insert(lines, "\t"..(nlevel==0 and ">" or " ").."("..nlevel..") "..line); |
| 149 local npadding = (" "):rep(#tostring(nlevel)); | 151 local npadding = (" "):rep(#tostring(nlevel)); |
| 150 local locals_str = string_from_var_table(level.locals, 65, "\t "..npadding); | 152 local locals_str = string_from_var_table(level.locals, optimal_line_length, "\t "..npadding); |
| 151 if locals_str then | 153 if locals_str then |
| 152 table.insert(lines, "\t "..npadding.."Locals: "..locals_str); | 154 table.insert(lines, "\t "..npadding.."Locals: "..locals_str); |
| 153 end | 155 end |
| 154 local upvalues_str = string_from_var_table(level.upvalues, 65, "\t "..npadding); | 156 local upvalues_str = string_from_var_table(level.upvalues, optimal_line_length, "\t "..npadding); |
| 155 if upvalues_str then | 157 if upvalues_str then |
| 156 table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str); | 158 table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str); |
| 157 end | 159 end |
| 158 end | 160 end |
| 159 | 161 |
| 160 local padding = string.rep("-", math.floor(((65 - 6) - #last_source_desc) / 2)); | 162 local padding = string.rep("-", math.floor(((optimal_line_length - 6) - #last_source_desc) / 2)); |
| 161 table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ ")); | 163 table.insert(lines, "\t ^"..padding.." "..last_source_desc.." "..padding..(#last_source_desc%2==0 and "-^" or "^ ")); |
| 162 | 164 |
| 163 return message.."stack traceback:\n"..table.concat(lines, "\n"); | 165 return message.."stack traceback:\n"..table.concat(lines, "\n"); |
| 164 end | 166 end |
