lua-users home
lua-l archive

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


On Thu, Apr 1, 2010 at 12:18 AM, Vaughan McAlley <ockegheim@gmail.com> wrote:
> Do you mean when objects of different schemes try to talk to each
> other?

Specifically when you try to inherit from a 'class' that is
implemented by a different scheme. ('class' in quotes because the
concept is not basic to Lua)

> newObject = setmetatable( {}, { __index = parentObject })

That's one scheme; your class is a metatable, which has a 'fallback'
__index pointing at the parent class, giving you an inheritance chain.
This can hurt performance, so there's also 'fat metatable' inheritance
where the base class members are copied into the metatable.  Classes
get a little fatter, but assuming that there are many more objects
than classes this is a fine trade-off.

If the number of objects of a given class are small, then
closure-based classes are faster but you pay more per object.

But if the 'class' is a metatable, then the inheritance chaining
method should work with it.

steve d.

http://lua-users.org/wiki/LuaClassesWithMetatable