lua-users home
lua-l archive

RE: Next Version of Lua?

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


If this were a democracy (which it isn't probably explaining why we do not
have a 'Swiss Army Chainsaw'), I'd vote for a '__iter' metamethod so you
could provide a customised iterator factory for an object class. This would
allow syntax:
for k,v in obj do ... end
rather than the present (and in my no doubt controversial view, ugly and
error-prone):
for k,v in pairs(obj) do ... end
As a side note, I 'bodge' this using the '__call' metamethod in my own
object classes so I can write:
for k,v in obj() do ... end
Which is close, but not ideal particularly if you want to use '__call' for
something else as well. However it is sometimes neat to be able to
parameterise the iterator factory as you can with a '__call' override, for
example to specify iteration over a sub-list. It would be neat if this could
be allowed with '__iter', but you should be able to omit empty parenthesis
in this case.
> Metamethods:
> * VM: Add support for __ne, __gt, and __ge (not equal, greater than,
> greater than or equal to); Would this impact performance in any
> significant way?
> * VM: Add support for __overrideindex (as the meta-method's name
> suggest, override a key in the table which already contains a non-nil
> value with a new value, nil or otherwise)
> * VM: Add support for __finalize (do-able? or would it drive the
> collector insane?)
> 

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