[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: metatable transmission
- From: Javier Guerra <javier@...>
- Date: Mon, 21 Dec 2009 14:54:57 -0500
On Mon, Dec 21, 2009 at 2:45 PM, spir <denis.spir@free.fr> wrote:
>> 'fat metatable' inheritance
>
> What do you mean?
each class is defined by the common metatable; but for sharing methods
between classes there are two main different implementations:
- model strict inheritance: if class B inherits from class A; add A's
metatable as a metatable to B's metatable. the LuaVM will follow the
chain.
- 'fat metatables': if class B inherits from class A, just copy all
methods from A to B before defining B's extra and overriding methods.
after all, you're copying only references, and the copy process will
be executed only once at startup time. it's faster since the LuaVM
will do just a single 'fallback' to a metatable, and also lets you
pick and mix from different classes; adding mixins and maybe not
inheriting everything. in fact, makes inheritance just a shorthand
for some common cases without forcing you to express everything in a
hierarchy.
--
Javier