lua-users home
lua-l archive

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


John Hind wrote:
> This allows the Table and Userdata types to have type metatables without
> losing their current per-object ones. This new mechanism is then used to
> expose the Table Library as methods of Table objects in the same way the
> String Library is exposed for String objects.

I like this idea a lot! How does this work, exactly- if an object already
has an __index function, is a lookup for a generic method only performed
when the __index- function returns nil (errors?), or not at all?
"Sparse" (frequent lookup of nonexistent keys) tables also become slightly
more expensive with this change, I suppose?

> While there, you could maybe take another look at my
> 'Self-iterating Objects' patch further down the same page.

I think this is the most convincing proposal for a Lua-syntax change I've
seen this far. I've observed Lua-beginners trying to do table-iteration
with exactly this pattern repeatedly ("for k, v in t do ...")- even to me,
after years of Lua-exposure, this still looks more intuitive.

IMHO, omitting the "pairs(.)" in a for-loop for this syntax is both more
concise *and* comprehensible (for a beginner), while "(__)ipairs" is simply
not useful enough (hardly useful *at all* AFAICT) to warrant maintaining
the current rules.

I strongly believe that this would make Lua syntax more "natural" and
would really like to hear peoples opinion on this because it looks too
good to let discussion about it die before it even started...

--Wolfgang