Software /
code /
prosody
Comparison
util/debug.lua @ 4777:74ae0433f8dd
util.debug: Re-fix parameter handling (I think it matches debug.traceback() more accurately now) and document level fudge
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 28 Apr 2012 16:20:26 +0100 |
parent | 4699:c66179261551 |
child | 4778:127de6eec433 |
comparison
equal
deleted
inserted
replaced
4776:dbe9d75c0452 | 4777:74ae0433f8dd |
---|---|
117 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 ")); | 117 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 ")); |
118 end | 118 end |
119 | 119 |
120 function _traceback(thread, message, level) | 120 function _traceback(thread, message, level) |
121 | 121 |
122 if type(thread) ~= "thread" then | 122 -- Lua manual says: debug.traceback ([thread,] [message [, level]]) |
123 -- I fathom this to mean one of: | |
124 -- () | |
125 -- (thread) | |
126 -- (message, level) | |
127 -- (thread, message, level) | |
128 | |
129 if thread == nil then -- Defaults | |
130 thread, message, level = coroutine.running(), message, level; | |
131 elseif type(thread) == "string" then | |
123 thread, message, level = coroutine.running(), thread, message; | 132 thread, message, level = coroutine.running(), thread, message; |
133 elseif type(thread) ~= "thread" then | |
134 return nil; -- debug.traceback() does this | |
124 end | 135 end |
125 if level and type(message) ~= "string" then | 136 |
126 return nil, "invalid message"; | 137 level = level or 1; |
127 elseif not level then | 138 |
128 if type(message) == "number" then | |
129 level, message = message, nil; | |
130 else | |
131 level = 1; | |
132 end | |
133 end | |
134 | |
135 message = message and (message.."\n") or ""; | 139 message = message and (message.."\n") or ""; |
136 | 140 |
141 -- +3 counts for this function, and the pcall() and wrapper above us | |
137 local levels = get_traceback_table(thread, level+3); | 142 local levels = get_traceback_table(thread, level+3); |
138 | 143 |
139 local last_source_desc; | 144 local last_source_desc; |
140 | 145 |
141 local lines = {}; | 146 local lines = {}; |