Mercurial > prosody-hg
comparison util/debug.lua @ 8382:e5d00bf4a4d5
util: Various minor changes to please [luacheck]
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 10 Nov 2017 05:42:32 +0100 |
| parents | cd15fc505b62 |
| children | 37dc2a6144d1 |
comparison
equal
deleted
inserted
replaced
| 8381:7f6184474149 | 8382:e5d00bf4a4d5 |
|---|---|
| 111 return levels; | 111 return levels; |
| 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, "v"..padding).." "..getstring(styles.filename, last_source_desc).." "..getstring(styles.boundary_padding, padding..(#last_source_desc%2==0 and "-v" or "v ")); | 116 return getstring(styles.boundary_padding, "v"..padding).." ".. |
| 117 getstring(styles.filename, last_source_desc).." ".. | |
| 118 getstring(styles.boundary_padding, padding..(#last_source_desc%2==0 and "-v" or "v ")); | |
| 117 end | 119 end |
| 118 | 120 |
| 119 local function _traceback(thread, message, level) | 121 local function _traceback(thread, message, level) |
| 120 | 122 |
| 121 -- Lua manual says: debug.traceback ([thread,] [message [, level]]) | 123 -- Lua manual says: debug.traceback ([thread,] [message [, level]]) |
| 141 local levels = get_traceback_table(thread, level+(thread == nil and 4 or 0)); | 143 local levels = get_traceback_table(thread, level+(thread == nil and 4 or 0)); |
| 142 | 144 |
| 143 local last_source_desc; | 145 local last_source_desc; |
| 144 | 146 |
| 145 local lines = {}; | 147 local lines = {}; |
| 146 for nlevel, level in ipairs(levels) do | 148 for nlevel, current_level in ipairs(levels) do |
| 147 local info = level.info; | 149 local info = current_level.info; |
| 148 local line = "..."; | 150 local line; |
| 149 local func_type = info.namewhat.." "; | 151 local func_type = info.namewhat.." "; |
| 150 local source_desc = (info.short_src == "[C]" and "C code") or info.short_src or "Unknown"; | 152 local source_desc = (info.short_src == "[C]" and "C code") or info.short_src or "Unknown"; |
| 151 if func_type == " " then func_type = ""; end; | 153 if func_type == " " then func_type = ""; end; |
| 152 if info.short_src == "[C]" then | 154 if info.short_src == "[C]" then |
| 153 line = "[ C ] "..func_type.."C function "..getstring(styles.location, (info.name and ("%q"):format(info.name) or "(unknown name)")); | 155 line = "[ C ] "..func_type.."C function "..getstring(styles.location, (info.name and ("%q"):format(info.name) or "(unknown name)")); |
| 159 name = ("%q"):format(name); | 161 name = ("%q"):format(name); |
| 160 end | 162 end |
| 161 if func_type == "global " or func_type == "local " then | 163 if func_type == "global " or func_type == "local " then |
| 162 func_type = func_type.."function "; | 164 func_type = func_type.."function "; |
| 163 end | 165 end |
| 164 line = "[Lua] "..getstring(styles.location, info.short_src.." line "..info.currentline).." in "..func_type..getstring(styles.funcname, name).." (defined on line "..info.linedefined..")"; | 166 line = "[Lua] "..getstring(styles.location, info.short_src.." line ".. |
| 167 info.currentline).." in "..func_type..getstring(styles.funcname, name).. | |
| 168 " (defined on line "..info.linedefined..")"; | |
| 165 end | 169 end |
| 166 if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous | 170 if source_desc ~= last_source_desc then -- Venturing into a new source, add marker for previous |
| 167 last_source_desc = source_desc; | 171 last_source_desc = source_desc; |
| 168 table.insert(lines, "\t "..build_source_boundary_marker(last_source_desc)); | 172 table.insert(lines, "\t "..build_source_boundary_marker(last_source_desc)); |
| 169 end | 173 end |
| 170 nlevel = nlevel-1; | 174 nlevel = nlevel-1; |
| 171 table.insert(lines, "\t"..(nlevel==0 and ">" or " ")..getstring(styles.level_num, "("..nlevel..") ")..line); | 175 table.insert(lines, "\t"..(nlevel==0 and ">" or " ")..getstring(styles.level_num, "("..nlevel..") ")..line); |
| 172 local npadding = (" "):rep(#tostring(nlevel)); | 176 local npadding = (" "):rep(#tostring(nlevel)); |
| 173 if level.locals then | 177 if current_level.locals then |
| 174 local locals_str = string_from_var_table(level.locals, optimal_line_length, "\t "..npadding); | 178 local locals_str = string_from_var_table(current_level.locals, optimal_line_length, "\t "..npadding); |
| 175 if locals_str then | 179 if locals_str then |
| 176 table.insert(lines, "\t "..npadding.."Locals: "..locals_str); | 180 table.insert(lines, "\t "..npadding.."Locals: "..locals_str); |
| 177 end | 181 end |
| 178 end | 182 end |
| 179 local upvalues_str = string_from_var_table(level.upvalues, optimal_line_length, "\t "..npadding); | 183 local upvalues_str = string_from_var_table(current_level.upvalues, optimal_line_length, "\t "..npadding); |
| 180 if upvalues_str then | 184 if upvalues_str then |
| 181 table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str); | 185 table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str); |
| 182 end | 186 end |
| 183 end | 187 end |
| 184 | 188 |
