X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;ds=sidebyside;f=util%2Fdebug.lua;h=bff0e347a22fa7b58676e280484c9e017bc8f24b;hb=ea9c53231bbd3b3b280389b63380944f5b0fadb8;hp=16773cd18a28ec48bf84c42d01132bef3e7eb761;hpb=727950066f8ddd7801082b225013fb2f21e07f43;p=prosody.git diff --git a/util/debug.lua b/util/debug.lua index 16773cd1..bff0e347 100644 --- a/util/debug.lua +++ b/util/debug.lua @@ -15,7 +15,7 @@ local styles; do _ = termcolours.getstyle; styles = { - boundary_padding = _("bright", "white"); + boundary_padding = _("bright"); filename = _("bright", "blue"); level_num = _("green"); funcname = _("yellow"); @@ -97,7 +97,7 @@ function get_traceback_table(thread, start_level) levels[(level-start_level)+1] = { level = level; info = info; - locals = get_locals_table(level); + locals = get_locals_table(level+1); upvalues = get_upvalues_table(info.func); }; end @@ -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;