# HG changeset patch # User Matthew Wild # Date 1335626426 -3600 # Node ID 74ae0433f8dddbfddbb46f779add054f60acf9e3 # Parent dbe9d75c04528a1cb5c721088a5bb496fd80399e util.debug: Re-fix parameter handling (I think it matches debug.traceback() more accurately now) and document level fudge diff -r dbe9d75c0452 -r 74ae0433f8dd util/debug.lua --- a/util/debug.lua Sat Apr 28 15:47:43 2012 +0100 +++ b/util/debug.lua Sat Apr 28 16:20:26 2012 +0100 @@ -119,21 +119,26 @@ 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;