Comparison

util/debug.lua @ 4524:816c319a09d8

util.debug: Add a touch of colour to source locations
author Matthew Wild <mwild1@gmail.com>
date Thu, 22 Mar 2012 16:39:28 +0000
parent 4523:d733bde93074
child 4525:e00b4ec5fca4
comparison
equal deleted inserted replaced
4523:d733bde93074 4524:816c319a09d8
17 styles = { 17 styles = {
18 boundary_padding = _("bright", "white"); 18 boundary_padding = _("bright", "white");
19 filename = _("bright", "blue"); 19 filename = _("bright", "blue");
20 level_num = _("green"); 20 level_num = _("green");
21 funcname = _("yellow"); 21 funcname = _("yellow");
22 location = _("yellow");
22 }; 23 };
23 end 24 end
24 25
25 local function get_locals_table(level) 26 local function get_locals_table(level)
26 level = level + 1; -- Skip this function itself 27 level = level + 1; -- Skip this function itself
141 local line = "..."; 142 local line = "...";
142 local func_type = info.namewhat.." "; 143 local func_type = info.namewhat.." ";
143 local source_desc = (info.short_src == "[C]" and "C code") or info.short_src or "Unknown"; 144 local source_desc = (info.short_src == "[C]" and "C code") or info.short_src or "Unknown";
144 if func_type == " " then func_type = ""; end; 145 if func_type == " " then func_type = ""; end;
145 if info.short_src == "[C]" then 146 if info.short_src == "[C]" then
146 line = "[ C ] "..func_type.."C function "..(info.name and ("%q"):format(info.name) or "(unknown name)") 147 line = "[ C ] "..func_type.."C function "..getstring(styles.location, (info.name and ("%q"):format(info.name) or "(unknown name)"));
147 elseif info.what == "main" then 148 elseif info.what == "main" then
148 line = "[Lua] "..info.short_src.." line "..info.currentline; 149 line = "[Lua] "..getstring(styles.location, info.short_src.." line "..info.currentline);
149 else 150 else
150 local name = info.name or " "; 151 local name = info.name or " ";
151 if name ~= " " then 152 if name ~= " " then
152 name = ("%q"):format(name); 153 name = ("%q"):format(name);
153 end 154 end
154 if func_type == "global " or func_type == "local " then 155 if func_type == "global " or func_type == "local " then
155 func_type = func_type.."function "; 156 func_type = func_type.."function ";
156 end 157 end
157 line = "[Lua] "..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..")";
158 end 159 end
159 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
160 if last_source_desc then 161 if last_source_desc then
161 table.insert(lines, "\t "..build_source_boundary_marker(last_source_desc)); 162 table.insert(lines, "\t "..build_source_boundary_marker(last_source_desc));
162 end 163 end