aboutsummaryrefslogtreecommitdiffstats
path: root/util/debug.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-04-28 16:20:26 +0100
committerMatthew Wild <mwild1@gmail.com>2012-04-28 16:20:26 +0100
commit04a6860173205a9cb77d3441e1bb04191d3ab020 (patch)
tree984e4bfd67f0dee9c58d06e71a6e28f30ebccd3a /util/debug.lua
parente8d147c96a9cf84cae6a957adc16cb0a9cd11360 (diff)
downloadprosody-04a6860173205a9cb77d3441e1bb04191d3ab020.tar.gz
prosody-04a6860173205a9cb77d3441e1bb04191d3ab020.zip
util.debug: Re-fix parameter handling (I think it matches debug.traceback() more accurately now) and document level fudge
Diffstat (limited to 'util/debug.lua')
-rw-r--r--util/debug.lua27
1 files changed, 16 insertions, 11 deletions
diff --git a/util/debug.lua b/util/debug.lua
index 1d3b5648..321b3267 100644
--- a/util/debug.lua
+++ b/util/debug.lua
@@ -119,21 +119,26 @@ end
function _traceback(thread, message, level)
- if type(thread) ~= "thread" then
+ -- Lua manual says: debug.traceback ([thread,] [message [, level]])
+ -- I fathom this to mean one of:
+ -- ()
+ -- (thread)
+ -- (message, level)
+ -- (thread, message, level)
+
+ if thread == nil then -- Defaults
+ thread, message, level = coroutine.running(), message, level;
+ elseif type(thread) == "string" then
thread, message, level = coroutine.running(), thread, message;
+ elseif type(thread) ~= "thread" then
+ return nil; -- debug.traceback() does this
end
- if level and type(message) ~= "string" then
- return nil, "invalid message";
- elseif not level then
- if type(message) == "number" then
- level, message = message, nil;
- else
- level = 1;
- end
- end
-
+
+ level = level or 1;
+
message = message and (message.."\n") or "";
+ -- +3 counts for this function, and the pcall() and wrapper above us
local levels = get_traceback_table(thread, level+3);
local last_source_desc;