JakobOvrum/LuaD

support for class inheritance

Trass3r opened this issue · 4 comments

Sooner or later cross-border inheritance is needed.
I'm not sure if exposing D's class hierarchy is necessary or possible (maybe for having an array of instances in lua, i.e. like CommonBaseClass[] in D?)

But I'm sure I'd like to be able to define custom classes in Lua as well as export certain D classes (e.g. MovingEntity) which can then be inherited in Lua. The other way around doesn't make much sense to me.

The question is in which ways this could be achieved.

I would have wanted you to post this in the issue "Expand on class conversion support".

This feature is not of very high priority right now, there are a lot of fundamental class conversion issues that need to be fixed first. As for implementing it, I'm sure it's not too hard considering the ABI is well specified for this and the runtime is very transparent. At any rate, it would come after exposure of classes (right now you can only expose class instances).

Sry, I opened a new issue cause this is not a basic problem with class conversion, it's more like an enhancement :)
A simple form of OOP is described in pil: http://www.lua.org/pil/index.html#16
Another approach can be found in CorsixTH: http://code.google.com/p/corsix-th/source/browse/trunk/CorsixTH/Lua/class.lua

I think a model tailored for deriving from D classes would be best, and keep functionality aimed at that and little else. If the user wants a broader object model, he can implement it on top in whichever flavour he prefers, or write a compatibility factory function for whatever object model he likes.

I registerClass a base class, then the derived class, and the derived objects cannot use base class's public methods (calling a nil value).