lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thank you all for your fast help! A quick look into luaconf.h reveals the following:
/*
@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
** CHANGE it to undefined as soon as your programs use only '...' to
** access vararg parameters (instead of the old 'arg' table).
**
** Note: this has a slightly negative performance impact with LuaJIT
** for all vararg functions. Leave it off if possible and upgrade your
** code (replace unpack(arg) with ... and/or add local arg = {...}).
*/
#undef LUA_COMPAT_VARARG

I tried by adding "local arg={...}" and it works well. We already have tons of lua code written in the old way, but it is only a matter of time to upgrade them. Thank you very much.

Regards
Long

KHMan ??:
Jean-Claude Wippler wrote:
--- begin of test.lua
function test(...)
for i=1, #arg do
print(arg[i])
end
end
[snip snip]
function test(...)
  for i=1, select("#",...) do
    print((select(i,...)))
  end
end

test(1,2,3)

(or use "{...}" to convert the varargs into a table)

In short, arg is a deprecated feature for 5.1 and is compiled in
some Lua binaries for compatibility purposes. The LuaJIT you are
using may not have such compatibility features compiled in and as
such, you may need to consider recompilation or a Lua codebase
update. A small price to pay for staying trim and slim. :-)