lua-users home
lua-l archive

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


Alex Bilyk escribió:

>>
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?
<<

1) Alex, that is *exactly* what I did in the sample code I posted.

2) I figure metatables are fair game. If I want to add my own keys to them
and redefine standard library functions to use them, that´s between me and
the libraries I use :)


Peter Hill escribió:

> Lua is currently half way to making user simulated table behaviour (with
> __index & __newindex). How about going the rest of the way with a __next
> metamethod?

> Note: I'd use "__next" rather than "__pairs" because it is more
fundamental.

My original thought was a __next metamethod. But after I tried writing a
few of them, I decided that __pairs is actually a lot easier to implement
in many interesting cases. Try a few and see for yourself...

Rici