Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting arg to work in a varag function in Lua 5.2 (integrated in Delphi)

Tags:

delphi

lua

When using the Lua 5.2 API, the code below prints "nil"

function __debug(szName, ...)
    print(type(arg));
end

__debug("s", 1, 2, 3, 4);

But this code does work when using Lua 5.1, and prints "table"

like image 876
Samoongeer Avatar asked Dec 09 '22 01:12

Samoongeer


2 Answers

If you are referring to vararg function, the arg table was deprecated already in Lua 5.1. In Lua 5.2, you can use table.pack to create arg if you need it:

function debug(name, ...)
    local arg = table.pack(...)
    print(name)
    for i=1,arg.n do
        print(i, arg[i])
    end
end
like image 193
Michal Kottman Avatar answered May 22 '23 08:05

Michal Kottman


That's because arg has been deprecated since Lua 5.1. It only remained as a compatibility feature.

References: Lua 5.1 manual, unofficial LuaFaq

a workaround is using this line to generate a table called arg:

local arg={...}
like image 21
jpjacobs Avatar answered May 22 '23 09:05

jpjacobs