Skip to content

Instantly share code, notes, and snippets.

@CoderPuppy
Created January 7, 2016 20:29
Show Gist options
  • Select an option

  • Save CoderPuppy/cb3ae9cc42185c88313b to your computer and use it in GitHub Desktop.

Select an option

Save CoderPuppy/cb3ae9cc42185c88313b to your computer and use it in GitHub Desktop.
Lua stack trace using xpcall
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
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