Software /
code /
prosody
Annotate
util/debug.lua @ 4588:3e7702891649
Merge with Zash
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 03 Mar 2012 18:27:32 +0000 |
parent | 4465:41c4252526bd |
child | 4519:510f4ba7080f |
child | 4680:8834f220ab91 |
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) |
4465
41c4252526bd
util.debug: Adjust level within get_locals_table() to account for the additional depth of this function itself
Matthew Wild <mwild1@gmail.com>
parents:
4418
diff
changeset
|
12 level = level + 1; -- Skip this function itself |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local locals = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 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
|
15 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
|
16 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
|
17 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
|
18 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 return locals; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 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
|
23 local upvalues = {}; |
4418
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
24 if func then |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
25 for upvalue_num = 1, math.huge do |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
26 local name, value = debug.getupvalue(func, upvalue_num); |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
27 if not name then break; end |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
28 table.insert(upvalues, { name = name, value = value }); |
70b5e533325d
util.debug: Fix potential traceback
Matthew Wild <mwild1@gmail.com>
parents:
4412
diff
changeset
|
29 end |
4412
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 return upvalues; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 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
|
35 local var_string = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local col_pos = 0; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 value = "<hidden>"; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 value = ("%q"):format(value); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 value = tostring(value); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 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
|
52 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
|
53 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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
|
58 col_pos = 0; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 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
|
61 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 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
|
64 return nil; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 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
|
67 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 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
|
71 local levels = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 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
|
73 local info; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 if thread then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 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
|
76 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 info = debug.getinfo(level); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 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
|
80 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 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
|
82 level = level; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 info = info; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 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
|
85 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
|
86 }; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 return levels; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 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
|
96 return nil, "invalid message"; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 elseif not level then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 level = message or 2; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 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
|
102 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 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
|
104 |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 local lines = {}; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 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
|
107 local info = level.info; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 local line = "..."; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 else |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 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
|
117 if name ~= " " then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 name = ("%q"):format(name); |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 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
|
121 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
|
122 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 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
|
124 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 nlevel = nlevel-1; |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 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
|
127 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
|
128 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
|
129 if locals_str then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 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
|
131 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 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
|
133 if upvalues_str then |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 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
|
135 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 end |
5d7d9a60bc7f
util.debug: Experimental new library for producing more extensive debug tracebacks
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 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
|
138 end |