diff options
author | Matthew Wild <mwild1@gmail.com> | 2012-04-24 21:59:20 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2012-04-24 21:59:20 +0100 |
commit | 15175bb828ab14cf0f35b221227beeeb46e4dd8f (patch) | |
tree | fe8c013599dd847f7365cb1adab80ab8fe846de5 /util/debug.lua | |
parent | a5efef5aab5624e3a1cb4f1966e719738b859eda (diff) | |
parent | 7cb22f77a78741a1bd085c6b3dc3b31f51c1fa09 (diff) | |
download | prosody-15175bb828ab14cf0f35b221227beeeb46e4dd8f.tar.gz prosody-15175bb828ab14cf0f35b221227beeeb46e4dd8f.zip |
Merge timber->trunk - thanks everyone!
Diffstat (limited to 'util/debug.lua')
-rw-r--r-- | util/debug.lua | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/util/debug.lua b/util/debug.lua index 3736dd34..7caf21ce 100644 --- a/util/debug.lua +++ b/util/debug.lua @@ -22,8 +22,9 @@ do location = _("yellow"); }; end +module("debugx", package.seeall); -local function get_locals_table(level) +function get_locals_table(level) level = level + 1; -- Skip this function itself local locals = {}; for local_num = 1, math.huge do @@ -34,7 +35,7 @@ local function get_locals_table(level) return locals; end -local function get_upvalues_table(func) +function get_upvalues_table(func) local upvalues = {}; if func then for upvalue_num = 1, math.huge do @@ -46,7 +47,7 @@ local function get_upvalues_table(func) return upvalues; end -local function string_from_var_table(var_table, max_line_len, indent_str) +function string_from_var_table(var_table, max_line_len, indent_str) local var_string = {}; local col_pos = 0; max_line_len = max_line_len or math.huge; @@ -103,8 +104,8 @@ function get_traceback_table(thread, start_level) return levels; end -function debug.traceback(...) - local ok, ret = pcall(debug._traceback, ...); +function traceback(...) + local ok, ret = pcall(_traceback, ...); if not ok then return "Error in error handling: "..ret; end @@ -116,7 +117,8 @@ local function build_source_boundary_marker(last_source_desc) 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 ")); end -function debug._traceback(thread, message, level) +function _traceback(thread, message, level) + if type(thread) ~= "thread" then thread, message, level = coroutine.running(), thread, message; end @@ -178,3 +180,9 @@ function debug._traceback(thread, message, level) return message.."stack traceback:\n"..table.concat(lines, "\n"); end + +function use() + debug.traceback = traceback; +end + +return _M; |