lua-users home
lua-l archive

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


Michael Gogins wrote:
> What about inheritance and virtual methods, then?

It's build-your-own, just like with table-based Lua class systems.

The best way to do it for the FFI metatypes, is to resolve the
inheritance chain during (dynamic) construction of a class. I.e.
merge the method table with its ancestors. Use a single flattened
__index table for each class, holding a copy of all the applicable
methods (whether inherited or not).

Virtual or abstract methods are a non-issue for Lua class systems.
There's no type checking of method signatures, so you can simply
override them by name.

<rant>
However I strongly suggest to resist the initial impulse to build
up a complex class system for Lua. Inheritance is overrated, anyway.

It seems to be a common reflex of programmers coming from other
languages to build up their dream of a class system for Lua as
their first task. Learning how to actually write good code in Lua
is skipped of course, because the language looks so easy, right?

Many months later, they still have no application to speak of, but
an overly complex, slow and entirely useless framework that's
quickly abandoned right after blogging how horrible their whole
Lua experience was. :-)
</rant>

--Mike