Skip to content

Instantly share code, notes, and snippets.

@pkulchenko
Last active August 29, 2015 14:20
Show Gist options
  • Save pkulchenko/c03310fbd897c4a7c081 to your computer and use it in GitHub Desktop.
Save pkulchenko/c03310fbd897c4a7c081 to your computer and use it in GitHub Desktop.
Mobdebug patch to enable vararg handling
diff --git a/lualibs/mobdebug/mobdebug.lua b/lualibs/mobdebug/mobdebug.lua
index 89d6be4..618f8fb 100644
--- a/lualibs/mobdebug/mobdebug.lua
+++ b/lualibs/mobdebug/mobdebug.lua
@@ -274,12 +274,22 @@ local function stack(start)
local func = debug.getinfo(f, "f").func
local i = 1
local locals = {}
+ -- get locals
while true do
local name, value = debug.getlocal(f, i)
if not name then break end
if string.sub(name, 1, 1) ~= '(' then locals[name] = {value, tostring(value)} end
i = i + 1
end
+ -- get varargs (these use negative indices)
+ i = 1
+ while true do
+ local name, value = debug.getlocal(f, -i)
+ if not name then break end
+ locals[name:gsub("%)$"," "..i..")")] = {value, tostring(value)}
+ i = i + 1
+ end
+ -- get upvalues
i = 1
local ups = {}
while func and true do -- check for func as it may be nil for tail calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment