VSCodeLuaDebug icon indicating copy to clipboard operation
VSCodeLuaDebug copied to clipboard

I think this line should use t.n instead of #t

Open fxrc2018 opened this issue 1 year ago • 1 comments

https://github.com/devcat-studio/VSCodeLuaDebug/blob/61c3de71ee192280daa4d6fcc7430ff2e197d67c/debuggee/vscode-debuggee.lua#L533

fxrc2018 avatar May 20 '24 15:05 fxrc2018

For context:

local t = { n = select("#", ...), ... }

Since this is redefining print, that means that ... could include nil so the resulting list table may have holes. I wouldn't expect # to count holes correctly, but in this case it on Lua 5.4.4 it does!

Test:

local function test1(...)
    local t = { n = select("#", ...), ... }
    print("#t", #t)
    for i = 1, #t do
        print(t[i])
    end
end

local function test2(...)
    local t = { n = select("#", ...), ... }
    print("t.n", t.n)
    for i = 1, t.n do
        print(t[i])
    end
end

local function test3(t)
    print("#t", #t)
    for i = 1, #t do
        print(t[i])
    end
end

test1(1, nil, nil, 2, 3)
print("\n")
test2(1, nil, nil, 2, 3)
print("\n")
test3{1, nil, nil, 2, 3}

Regardless, on luajit it drops everything after the first nil. So I think your change is correct.

idbrii avatar Jun 04 '24 23:06 idbrii