[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to overwrite/implement '__len'?
- From: Doug Rogers <rogers@...>
- Date: Tue, 13 Jun 2006 14:21:44 -0400
Clemens Hintze wrote:
> So I looked into the reference manual and it
> seems that my '__len' will never be called because type(Range) == "table".
> Now my question is: how do I possibly achieve my desire? It ought to be
> possible IMO, as tables are Lua's way to build more complex
> data structures...
Yes, like the __gc metamethod (but for different reasons - see
http://lua-users.org/lists/lua-l/2006-01/msg00172.html), __len can only
be overridden by userdatum types. Experience has taught me that there
will be a good reason for such an apparent oversight. It may just be
performance; see http://lua-users.org/lists/lua-l/2006-03/msg00700.html.
I don't see an easy way to avoid the cost of walking the metatable tree
for the case where __len is not defined.
But perhaps there are other issues. I was unable to find any further
discussion in the archives, but I seem to remember more than what I found.
Doug Rogers - ICI - V:703.893.2007x220 www.innocon.com