[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Some conservative Lua metamethod extension proposals
- From: "John Hind" <john.hind@...>
- Date: Sat, 24 Mar 2018 10:34:41 +0000
First, sorry if I am missing some things you said, but this damn message system has had a bug for more than a decade now whereby some of the digest messages come through as hex gobblygook and I can only read them 24 hours or more later on the web archive (or if you copy me in on an individual message like you kindly did in this case)!
But I really do not understand where you are coming from. If you want a different iteration behaviour that applies to ALL tables, what is the benefit of making it a metamethod? Either sell that behaviour for the library version of 'pairs', or just write your own version with a different name. ('monkey-patching' is not only objectionable because of the brittle techniques used to achieve it, but because it causes unexpected and undocumented behaviour for users)
Also, my '__iter' metamethod proposal DOES support plain tables too - it defaults to an internal implementation functionally equivalent to 'pairs'. In other news, 'ipairs' is redundant with or without a metamethod since we have numeric for!
------ Original Message ------
Sent: 24/03/2018 09:50:15
Subject: Re: Some conservative Lua metamethod extension proposals
> for k, v in instanceofmyclass:pairs() do ... end
> for k, v in instanceofmyclass do ... end
I'm after code that's quite a bit more generic than this, and in particular supports plain tables.