Software /
code /
prosody
Annotate
util/debug.lua @ 4419:b1e49cc314cb
util.ip: New module containing IP related functions
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Sat, 22 Oct 2011 17:51:53 +0200 |
parent | 4418:70b5e533325d |
child | 4465:41c4252526bd |
rev | line source |
---|---|
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Variables ending with these names will not |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- have their values printed ('password' includes |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- 'new_password', etc.) |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local censored_names = { |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 password = true; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 passwd = true; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 pass = true; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 pwd = true; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 }; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local function get_locals_table(level) |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local locals = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 for local_num = 1, math.huge do |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local name, value = debug.getlocal(level, local_num); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 if not name then break; end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 table.insert(locals, { name = name, value = value }); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 return locals; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local function get_upvalues_table(func) |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local upvalues = {}; |
4418
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
23 if func then |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
24 for upvalue_num = 1, math.huge do |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
25 local name, value = debug.getupvalue(func, upvalue_num); |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
26 if not name then break; end |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
27 table.insert(upvalues, { name = name, value = value }); |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
28 end |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 return upvalues; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local function string_from_var_table(var_table, max_line_len, indent_str) |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local var_string = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local col_pos = 0; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 max_line_len = max_line_len or math.huge; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 indent_str = "\n"..(indent_str or ""); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 for _, var in ipairs(var_table) do |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local name, value = var.name, var.value; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 if name:sub(1,1) ~= "(" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 if type(value) == "string" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 if censored_names[name:match("%a+$")] then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 value = "<hidden>"; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 value = ("%q"):format(value); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 value = tostring(value); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 if #value > max_line_len then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 value = value:sub(1, max_line_len-3).."…"; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 local str = ("%s = %s"):format(name, tostring(value)); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 col_pos = col_pos + #str; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 if col_pos > max_line_len then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 table.insert(var_string, indent_str); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 col_pos = 0; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 table.insert(var_string, str); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 if #var_string == 0 then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 return nil; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 return "{ "..table.concat(var_string, ", "):gsub(indent_str..", ", indent_str).." }"; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 function get_traceback_table(thread, start_level) |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 local levels = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 for level = start_level, math.huge do |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 local info; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 if thread then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 info = debug.getinfo(thread, level); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 info = debug.getinfo(level); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 if not info then break; end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 levels[(level-start_level)+1] = { |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 level = level; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 info = info; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 locals = get_locals_table(level); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 upvalues = get_upvalues_table(info.func); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 }; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 return levels; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 function debug.traceback(thread, message, level) |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 if type(thread) ~= "thread" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 thread, message, level = coroutine.running(), thread, message; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 if level and type(message) ~= "string" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 return nil, "invalid message"; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 elseif not level then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 level = message or 2; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 message = message and (message.."\n") or ""; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 local levels = get_traceback_table(thread, level+2); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 local lines = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 for nlevel, level in ipairs(levels) do |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 local info = level.info; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 local line = "..."; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 local func_type = info.namewhat.." "; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 if func_type == " " then func_type = ""; end; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 if info.short_src == "[C]" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 line = "[ C ] "..func_type.."C function "..(info.name and ("%q"):format(info.name) or "(unknown name)") |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 elseif info.what == "main" then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 line = "[Lua] "..info.short_src.." line "..info.currentline; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 local name = info.name or " "; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 if name ~= " " then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 name = ("%q"):format(name); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 if func_type == "global " or func_type == "local " then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 func_type = func_type.."function "; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 line = "[Lua] "..info.short_src.." line "..info.currentline.." in "..func_type..name.." defined on line "..info.linedefined; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 nlevel = nlevel-1; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 table.insert(lines, "\t"..(nlevel==0 and ">" or " ").."("..nlevel..") "..line); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 local npadding = (" "):rep(#tostring(nlevel)); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 local locals_str = string_from_var_table(level.locals, 65, "\t "..npadding); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 if locals_str then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 table.insert(lines, "\t "..npadding.."Locals: "..locals_str); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 local upvalues_str = string_from_var_table(level.upvalues, 65, "\t "..npadding); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 if upvalues_str then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 table.insert(lines, "\t "..npadding.."Upvals: "..upvalues_str); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 return message.."stack traceback:\n"..table.concat(lines, "\n"); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 end |