Created
January 7, 2016 20:29
-
-
Save CoderPuppy/cb3ae9cc42185c88313b to your computer and use it in GitHub Desktop.
Lua stack trace using xpcall
This file contains hidden or 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
| test.lua:16: hi | |
| traceback | |
| 5 test.lua:16: @ | |
| 6 test.lua:21: @ | |
| 7 @ | |
| error hi | |
| traceback | |
| 2 test.lua:5: @ | |
| 3 test.lua:31: @ | |
| 4 test.lua:16: @ | |
| 5 test.lua:36: @ | |
| 6 @ | |
| test.lua:17: attempt to perform arithmetic on a string value |
This file contains hidden or 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
| xpcall(function() | |
| local function traceback(i) | |
| print('traceback') | |
| while true do | |
| local _, m = pcall(error, '@', i) | |
| print(i, m) | |
| if m == '@' then | |
| break | |
| end | |
| i = i + 1 | |
| if i > 100 then break end | |
| end | |
| end | |
| local function test() | |
| error('hi') | |
| print(1 + 'h') | |
| end | |
| xpcall(function() | |
| test() | |
| end, function(msg) | |
| print(msg) | |
| traceback(5) | |
| end) | |
| local oError = error | |
| local function errorOverride(msg) | |
| print('error', msg) | |
| _G.error = oError | |
| traceback(2) | |
| _G.error = errorOverride | |
| end | |
| _G.error = errorOverride | |
| test() | |
| end, print) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment