Skip to content

Instantly share code, notes, and snippets.

@DarkWiiPlayer
Last active February 11, 2021 17:26
Show Gist options
  • Save DarkWiiPlayer/42f83c5b6d06897464027c712420bfe0 to your computer and use it in GitHub Desktop.
Save DarkWiiPlayer/42f83c5b6d06897464027c712420bfe0 to your computer and use it in GitHub Desktop.
local tableview = require 'tableview'
local pegasus = require 'pegasus'
local print = function(...)
print(...)
io.stdout:flush()
end
local function serve(tab)
local server = pegasus:new {
port = 8080;
location = '/dev/null';
}
server:start(function(request, response)
response:addHeader("content-type", "text/html")
response:write(tableview.generate(tab))
end)
end
local function nlocal(i, n)
local name, value = debug.getlocal(i+1, n+1)
if name then
return n+1, name, value
end
end
local function locals(i)
return nlocal, i, 0
end
local function stack(index)
local result = {}
for i=index, math.huge do
local info = debug.getinfo(i+1)
if info then
local localtab = {}
for n, name, value in locals(i+1) do
if localtab[name] then
shadowed = shadowed or {}
shadowed[name] = shadowed[name] or {}
table.insert(shadowed[name], localtab[name])
end
localtab[name] = value
end
info.locals = localtab
info.locals["(shadowed)"] = shadowed
if _VERSION < "Lua 5.2" then
info.environment = getfenv(i+1)
end
result[i] = info
else
break
end
end
return result
end
--serve(stack(1))
--os.exit()
xpcall(function()
local foo = "shadowed"
local foo = "also shadowed"
local foo = "not shadowed"
local bar = { "nested", "table" }
error("REEEEE")
end, function(message)
--os.execute("xdg-open http://localhost:8080/")
serve {
["Error Message"] = message,
["Loaded Modules"] = package.loaded,
["Stack"] = stack(2),
}
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment