lua-users home
lua-l archive

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


> I have repeatedly suggested to remove this complexity from lua by making
> __index and __newindex be called always, independently of whether the
> specified key has a nil value.  This is what everyone would expect to 
> happen anyway.  I'm bored of posting about this and, obviously, so is 
> the list since no one answered to a recent suggestion having to do with 
> that (and other matters, see post: "Unified tables and userdata").
> 
> Dimitris

Hello Dimitris, I'm afraid you're a bit late to the game here.  I'm sorry
the lua-l group has ignored the points you wanted to discuss, but the
simple fact is that Lua is a fairly mature language (more than 10 years
old now) and the list has been over these issues very thoroughly in the
recent past.

If you do want to modify Lua, these are not difficult changes to make.

I agree that the default indexing metamethod behavior could be simpler, 
but there are good reasons for the current design, notably the huge 
performance hit if __index and __newindex were forced all the time.  The 
prominent use of Lua in embedded platforms and games makes table 
performance more important than meta-feature convenience, especially since 
tables are the fundamental Lua data structure.

However, I think this is a strong argument for increasing the ease of
using proxy tables, since they are a prominent idiom in Lua 5.  I've been 
thinking about adding the following:

1) A table internals swap (or identity swap if you like) function to
efficiently proxy a table without losing identity.

2) Having a per-table proxy-mode flag to force __index and __newindex use
regardless of existing keys.  This is a kind of self-proxy or auto-proxy
behavior.  It would be much cheaper than always checking metatables, and 
it doesn't require an extra table like the typical proxy idiom does.

These would allow use of either proxies or forced lookups (or both)  
conveniently, and are in the minimalist Lua spirit of extensibility.

Lua does have its rough edges and room for growth, and your suggestions 
and participation are appreciated even if they don't provoke debate.

-Lucas