lua-users home
lua-l archive

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

> -----Original Message-----
> From: []
> Sent: Thursday, March 06, 2003 3:15 PM
> To: Multiple recipients of list
> Subject: RE: Enumerating Inherited Properties
> Alex Bilyk escribió:
> >>
> You can do this with generalized 'for' construct in Lua 5. 
> All you have to
> do is to write a function that generates 'next' pair the way 
> *you* want it.
> For instance, one could write a generator function that 
> iterates through
> every sub-entry within a given table hierarchy or only some designated
> entries satisfying some criteria. In your case, the criteria 
> would be to
> pay attention to "__index" and include those into your 
> iteration domain. No
> new metamethods are needed for this.
> <<
> Of course, that is true. However, that assumes that you 
> always know the
> iteration type of the table you are trying to iterate. A general pairs
> function which consults the metatable to extra the __pairs 
> metamethod is
> not significantly slower than the existing pairs function, and avoids
> iterators having to intimately know their subjects.

You can implement this functionality in Lua itself by re-impelemting 'pairs' function from standard library to *your* linking. Otherwise, what if after you are done with your __pairs idea someone else pops up and says that it is still not enough for whatever reason and suggests to have another metaevent "__pairs_2" to accomodate for that whatever? Where do you draw the line?


> R.