lua-users home
lua-l archive

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


Hi,

John Belmonte wrote:
> >>>
> - Vararg syntax has changed.  Instead of ... that generates an
>   automatic arg parameter you now have to write name[].  So a
>   vararg function looks like this:
> 
>     function foo:bar(...) --> function foo:bar(self, arg[])
> <<<
> 
> I like this too.  However maybe a syntax like the following is
> better since it can be backwards compatible with Lua if you allow
> the name to be omitted:
> 
>     function foo(x, y, arg...)

I chose the arg[] form because of future changes.  The idea was
to make it valid in other places, too.  Mainly:

	local a,b,c[] = foo()

and

	foo(a,b,c[])

It basically becomes a pack/unpack operator.  And, I wanted to
reserve the dots (...) for an optimized version of that, namely
when you do not access the variable arguments but simply pass
them to other functions like this:

	function foo(x, y, ...)
		bar(x+y, ...)
	end

Here the varargs are really anonymous and, more important, it's
not necessary to create a real table!  Would greatly enhance the
performance of typical wrapper functions.

Ciao, ET.