[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lua hacking wondering
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 23 Jun 2004 12:47:37 -0300
> Wouldn't it be possible to store a pointer the the internal table
> structure of the metatable that is ssigned to each table/udata? That
> way the cost of checking wether a metamethod exists would be one
> pointer lookup and some bit testing wich is negligible (plus maybe
> some overhead in lua_setmetatable)
This is already done. I don't think metatable access is a performance
problem in real applications.
> and we would be able to have our precious __settable ,__gettable and
> maybe __next metamethods.
The point is not performance. Whenever you set a __gettable metamethod
to a table, you cannot access that table except through a "rawget" call.
In other words, you already need some special way to access the table.
That is not much different than the use of a proxy. More important, it
is quite easy to encapsulate the proxy "pattern" inside a function, so
that anyone that needs to track table accesses just call that function
(see PIL, page 117).
If people keep asking something, it does not imply that the language
needs that something built-in; it may mean only that it needs better
documentation (FAQ comes to mind :) or external libraries.