lua-users home
lua-l archive

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


2014-06-04 18:14 GMT+02:00 Andrew Starks <andrew.starks@trms.com>:

> I would think that the number of arguments passed into `ipairs` is  none of
> Lua's business... por que?

There was IIRC a somewhat similar point about __index not too long
ago, and the explanation was that the way __index (or pairs for that
matter) is documented, translates to a prescription for whatever
routine one wants tooverride it with.

So the manual says `ipairs (t)` and that means __ipairs
has one argument. (Of course, if you redefine `ipairs` itself
you can do what you like.)

There are just a few opportunities for cheating: monadic operators
like __neg, __bnot actually are called with two arguments,
and one can exploit that, if the possibility that it might not
work in future does not daunt you. The Lua 5.3 manual
does not state that __len works this way too, but it does.