[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: When does __index metamethod get called?
- From: Chris <coderight@...>
- Date: Thu, 16 Mar 2006 21:55:41 -0500
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