Skip to content

Instantly share code, notes, and snippets.

@exerro
Created February 27, 2017 20:56
Show Gist options
  • Save exerro/c485a15e3293e9cbf2e5d0d195ebdbc2 to your computer and use it in GitHub Desktop.
Save exerro/c485a15e3293e9cbf2e5d0d195ebdbc2 to your computer and use it in GitHub Desktop.
function Exception.traceback( level, count, userspace )
local trace = {}
level = (level or 1) + 1
if level > 2 then
local i = 1
while #trace < count do
local src = select( 2, pcall( error, "", level + i ) ):gsub( ": $", "" )
if src == "pcall" or src == "" then
break
else
local src_and_line
if __get_src_and_line then
local line, msg = src:match( "^" .. (select(2,pcall(error,"@",2)):match"^(.*):%d+: @$") .. ":(%d+)$" )
if line then
src, line = __get_src_and_line( tonumber( line ) )
src_and_line = src .. "[" .. line .. "]"
else
src_and_line = ("%s[%s]"):format( src:match "(.+):(%d+)" )
end
else
src_and_line = ("%s[%s]"):format( src:match "(.+):(%d+)" )
end
if not (userspace and src:find "^sheets%.") then
userspace = false
trace[#trace + 1] = src_and_line
end
end
i = i + 1
end
end
return trace
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment