lua-users home
lua-l archive

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


On Tue, 11 May 2010 16:53:58 +0300, HyperHacker <hyperhacker@gmail.com> wrote:

You mean select('#', ...)?

Yes. consider also:

local f = function(x, y, z, ...) print(select('#', x, y, z, ...)) end
f()
f(1,2,3,4,5,6,7,8)

outputs:

3
8

So, basically, the simplest way to write function that can test if some of it's
arguments were not supplied is:

function (...)
local x, y, z = ...
if select('#', ...) < 3 then
.  .  .

Which is almost OK, but looks funny (like C code from the K&R age)
and needs to call global "select" function.

The way vararg currently works, "#..."
wouldn't syntactically make sense, though I agree the way it currently
works is awkward and as I understand it's being changed in 5.2.

That's good news.