lua-users home
lua-l archive

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

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, __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
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