Created
February 21, 2017 18:05
-
-
Save exerro/153daedf5743cc4cf0a20f66dbca070b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local __debug_line_tracker={ | |
{16,0,"subdir.abc",2}, | |
{1,0,"test_build.main",4} | |
} | |
local function __get_src_and_line( line ) | |
for i = 1, #__debug_line_tracker do | |
local t = __debug_line_tracker[i] | |
if line >= t[1] and line <= t[1] + t[2] then | |
return t[3], t[4] + line - t[1] | |
end | |
line = line - t[1] | |
end | |
return "unknown source", 0 | |
end | |
local __debug_ok, __debug_err = pcall( function() | |
abc | |
a = 1 | |
end ) | |
if not __debug_ok then | |
if type( __debug_err ) == "string" then | |
local e = select( 2, pcall( error, "@", 2 ) ) | |
local src = e:match "^(.*):%d+: @$" | |
local line, msg = __debug_err:match( src .. ":(%d+): (.*)" ) | |
if line then | |
local src, line = __get_src_and_line( tonumber( line ) ) | |
return error( src .. "[" .. line .. "]: " .. (__get_err_msg and __get_err_msg( src, line, msg ) or msg), 0 ) | |
end | |
end | |
return error( __debug_err, 0 ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment