[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Idle v1.0
- From: Thomas Lauer <thomas.lauer@...>
- Date: Wed, 18 Nov 2009 12:33:47 +0000
steve donovan <email@example.com> wrote:
> On Wed, Nov 18, 2009 at 12:21 PM, Thomas Lauer <firstname.lastname@example.org> wrote:
> > I've tried to "orthogonalise" the available metamethods. The beauty of
> > metamethods is that if you don't want or need them, they are not getting
> > in the way, so I reckoned a more rounded spectrum would be helpful for
> > some applications.
> That seems a most desirable goal. The balance here is 'explainabilty',
> e.g. does it significantly complicate any description of table lookup?
That depends on the level (or user experience) the description is aimed
at. A simple description of how tables work and how they can be used in
a script is one thing; the metamethods don't come into play here.
On a deeper level, they do of course; in this case more methods mean
more scope for confusion. But that's always been the price to be paid
for added complexity.
> > http://lua-users.org/wiki/LuaPowerPatches
> quote: "__usedindex behaves exactly like __newindex but when the
> indexed key actually exists (value is overwritten). this allows simple
> implementation of read-only tables, mirroring C structures etc without
> slow/lengthy/fragile table proxying constructs."
> So, if you want a read-only table, you make __usedindex always return nil?
__usedindex (as implemented in Idle) works very similar to __newindex
but it's called if a field is already in the table. IOW, the return
value of __usedindex is not the relevant point here. The function called
by __usedindex (or __newindex) acts as a gatekeeper which decides
whether or not a certain assignment will go ahead (ie it either performs
it or it doesn't).