lua-users home
lua-l archive

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


2012/9/16 Fidelis Assis <fidelis.assis@gmail.com>:
> 2012/9/16 Petite Abeille <petite.abeille@gmail.com>:
>>
>> On Sep 16, 2012, at 7:59 PM, Fidelis Assis <fidelis.assis@gmail.com> wrote:
>>
>>> Anyway, I miss the short "for v in t".
>>
>> You can achieve the same effect by making your table 'callable' (i.e. __call) and return an appropriate iterator.
>
> Good, thanks for the suggestion. But doing this naturally with be even
> better :).
>

There's always a trade-off: extra convenience at the cost of reducing
error detection. At present, if you write " in tbl" it means at the very
least that you did not at that moment consciously decide whether it
should be "pairs" or "ipairs".  In order to ensure that such inattention
is in fact correct, you should have consciously assigned an appropriate
metamethod to __call.  This is sane behaviour which I would not like
to see sacrificed.

I think we've had before (but can't find) a discussion on an __iter
metamethod, with __call being the fallback if there is no __iter.