pkulchenko/MobDebug

can not eval ... varargs in lua5.4.x

Closed this issue · 5 comments

local function test_varargs(p1, ... )
    --
    local arg = {...}
    print(p1, ...)
end
test_varargs("1", 2, "你好", "SONY", 3.14)

put a breakpoint in the follow line

print(p1, ...)

when the breakpoint is triggered,
add watch '...' will get a result as
image
, but if use lua5.2-5.3 and luajit it will get a result as
image

@sonyps5201314, thank you for the report. It looks like Lua 5.4 changed the name of those variables from (*vararg) to (vararg).

This patch should fix this:

diff --git a/src/mobdebug.lua b/src/mobdebug.lua
index dc4ea68..b5a59c0 100644
--- a/src/mobdebug.lua
+++ b/src/mobdebug.lua
@@ -303,8 +303,7 @@ local function stack(start)
     i = 1
     while true do
       local name, value = debug.getlocal(f, -i)
-      -- `not name` should be enough, but LuaJIT 2.0.0 incorrectly reports `(*temporary)` names here
-      if not name or name ~= "(*vararg)" then break end
+      if not name then break end
       locals[name:gsub("%)$"," "..i..")")] = {value, select(2,pcall(tostring,value))}
       i = i + 1
     end
@@ -439,8 +438,7 @@ local function capture_vars(level, thread)
     else
       name, value = debug.getlocal(level, -i)
     end
-    -- `not name` should be enough, but LuaJIT 2.0.0 incorrectly reports `(*temporary)` names here
-    if not name or name ~= "(*vararg)" then break end
+    if not name then break end
     vars['...'][i] = value
     i = i + 1
   end

Yes, it works now! Thank you for fixing it so quickly.

It seems that this feature is not supported in Lua5.1, not LuaJIT.

Correct; it looks like Lua 5.1 didn't provide access to varargs through getlocal.

Okay, thanks.