lua-users home
lua-l archive

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


In message <000801c296da$4353fd90$784d533e@arena>, =?iso-8859-1?Q?Ignacio_Casta
=F1o?= writes:
> ok.onClick.add( app:exit )
> 
> that's not valid, but could be written as:
> 
> ok.onClick.add( app.exit, app )
> 
> the first sintax is more natural since you already do app:exit() to call the
> method. I'm wondering if 'app:exit' could be expanded to 'app.exit, app'
> when used as a function argument.

I thought about this a while ago:

Perhaps

  object:method

could be rewritten as

  ( function(...) return object.method(object, asargs(arg)) end )

where asargs is a function (that can be written in C) that takes a table,
a, and returns it as a number of return values (return
a[1],a[2],...,a[n]).

In other words t:f creates a closure that inserts t into the front of whatever
argument list it is called with and then calls t.f.  Obviously since
this would be done in the compiler the function asargs needn't be called
and needn't exist.

This rewrite also explains the semantics of ordinary method calls
(v:name being(...) being equivalent to v.name(v, ...)).  Of course
for the ordinary case t:f(x) then the closure does not need to
be generated and the compiler can just handle that case as it does
now.

It's more general but less simple (less simple to explain anyway) and of
course involves generating a closure.

Cheers,
 drj