[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: upcoming changes in Lua 5.2 [was Re: Location of a package]
- From: "Alex Davies" <alex.mania@...>
- Date: Thu, 21 Feb 2008 22:53:34 +0900
As you say, __index is supposed to be called for non-existent keys. ipairs
though, like a lot of the table library, does not respect __index even if
the key
is non-existent. An oversight imo, but I guess it must have some advantages
(?)...
The main difference is that in letting __ipairs be overriden you can change
the
order from 1, 2, n to 3, 8, 5, 1 or whatever else tickles your fancy. That
will
break any existing code which assumes ipairs always starts from 1 and counts
up
(I've been guilty of making this assumption before), but again I guess it
must
have some advantages =P.
- Alex
----- Original Message -----
From: "Ignacio Burgueño" <ignaciob@inconcertcc.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Thursday, February 21, 2008 11:05 PM
Subject: Re: upcoming changes in Lua 5.2 [was Re: Location of a package]
Jérôme Vuarand wrote:
First, I think that the above would be a very welcomed addition to Lua.
Second, in my opinion, __index and __ipairs (whatever the final semantics
may be) are not comparable. __index is triggered on access to non-existent
keys and __ipairs would be used to redefine the way an array-like table is
iterated, right?
Also, using the same metamethod for both cases will make it hard to
distinguish when you're indexing a table and when you're going to iterate
it.
Regards,
Ignacio Burgueño