lua-users home
lua-l archive

Re: When does __index metamethod get called?

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


On 3/16/06, D Burgess <dburgess@gmail.com> wrote:
One could argue that it is better than perfect because you
can define your own interface.
e.g.

> p = {1,2,3,4,5}
> t={};t=setmetatable(t, {__index=function(t,k) return p[k] end})
> t.next=function (t,v) return function(t,v) return next(p,v) end end
> for k,v in t:next() do print(k,v) end
1 1
2 2
3 3
4 4
5 5

pairs() doesn't work though. That's typically how I iterate anyway.

--
// Chris


AltStyle によって変換されたページ (->オリジナル) /