lua-users home
lua-l archive

Trailing nils in an argument list (Was: Definition of table.insert)

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


On Sun, Jan 09, 2011 at 04:51:00PM +0200, David Kastrup wrote:
> Dirk Laurie <dpl@sun.ac.za> writes:
> 
> > 6. insert(a,b) does not do the same as insert(a,b,nil). This 
> > behaviour would not be possible for a function of three arguments
> > written in Lua itself.
> 
> Huh?
> 
> function arity(...)
> return select('#',...)
> end
> print(arity(1,2),arity(1,2,nil))
> 
> returns
> 
> 2 3
> 
By 'a function of three arguments' I mean a function starting with e.g.
 function f(a,b,c)
No such function can give distinguish whether it is called as f(1,2)
rather than f(1,2,nil).
But I concede your point. You don't need C to write a Lua function
that can make that distinction.
Dirk

AltStyle によって変換されたページ (->オリジナル) /