lua-users home
lua-l archive

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


Ah, of course, thanks!

Regarding the competing proposals for the no-arguments case, why not go the
"give us the tools" route and have a metamethod for cases were the "function
arguments expected" error would otherwise result. Call this "__reference"
for the sake of argument.

1) Hamburg enthusiasts could use this metamethod on the function type to
implement their closure syntax.

2) "__iter" partisans could use this on table-based classes to implement
class-specific default iterator factories without consuming the "__call"
metamethod or requiring empty parenthesis.

3) Multiple-iterator-as-methods fans could again use this metamethod on the
function type to remove the need for empty parenthesis on parameterless
function calls. (Not ideal as it's global, but some of us might like this
behaviour generally anyway.)

Clearly 1 and 3 are still mutually exclusive, but we do get the choice which
behaviour we prefer (and many other possibilities would also be enabled that
we've not even thought of).

> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-
> bounces@bazar2.conectiva.com.br] On Behalf Of Luiz Henrique de
> Figueiredo
> Sent: 14 September 2009 17:13
> To: Lua list
> Subject: Re: Regarding the name 'pairs'

>
> meta = {__call=function(o,x,i) return next(o,i) end}