lua-users home
lua-l archive

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


On Wed, 19 Dec 2001, Edgar Toernig wrote:

> > - "easy inheritance": the tag methods for "gettable", "settable", and
> > "index" can be a table, instead of a function. In that case, to "call"
> > the tag method means to index that table. So, for A to inherit from B, we
> > just set the "index" field in its handler-table to B; for instance
> >
> >       metatable(A, {index=B})
>
> Hmm... If you do this, then _please_ honour the function (call) tag
> method of B and only do this redirection if it's not set!
>
> "Calling" tables allows much more things then this simple redirection.

But this simple redirection is *much* faster than a regular tag method.
(And even with a special semantics for ':' you still need `index' for
inheritance.) You can always say

  index = function (a,b) return B(a,b) end

to make sure `B' will be called (even being a table...).

-- Roberto