lua-users home
lua-l archive

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


Hi,

> Hmm, I notice that my new version (which I actually bothered to test this
> time!) happens to meet that condition, though I was not actively aiming
for
> it :-).

I figured.  Try your example on this:

t = {a=11}
setmetatable(t,{__index={a=44}, __next=tnext})

That'll keep Lua busy for a while.  :-)

As Rici Lake pointed out, a "__next" function will need some internal state
(in upvalues) and thus "pairs" must provide a different closure each time.
(Actually, you can do without an extra state, but the implementation that I
can think of is far less attractive than an "upvalued" one.)

Bye,
Wim