[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Why no pairs() for userdata, __len for tables?
- From: Thomas Lauer <thomas.lauer@...>
- Date: Thu, 19 Apr 2007 13:33:15 +0100
I have a userdatum that looks (almost) like a Lua table: accesses are
caught through __index/__newindex/__len. (Nifty, this metastuff.)
What I can't (but would like to) do, is iterating over this table with
the standard functions. Writing my own iterator is easy enough but it
feels inconsistent: with a "normal" table I'd use pairs() (or ipairs()).
There may be very good reasons why there's no metamethod support for
this. If so, can anyone light a candle?
In a similar vein, I've seen that the VM calls __len metamethods only
for non-table and non-string objects. Why not support __len for tables
as well? I have read-only tables (similar to the PiL example) that work
reasonably well... but they return 0 as their size.
I can patch Lua to my heart's content but perhaps this whole area could
be made a little more consistent for the next big release...?
--
cheers thomasl
web : http://thomaslauer.com/start