lua-users home
lua-l archive

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


Hi guys,

Once I was writing similar wrappers to emulate classes,
You can have a look:
https://github.com/marsgpl/lua-class/blob/master/test.lua

It is quite powerful and fast and supports multiple inheritance
(including calling parents).

However later I realized that it is an excessive overhead and that
functional programming is superior (just my opinion).

On Sun, Nov 5, 2023 at 7:55 AM rzvxa <rzvxa@protonmail.com> wrote:
>
> Hello,
>
> You can keep a reference to the parent class metatable as the super and do something like this:
> function Aa:f(x)
>     Aa.super.f(self, x)
> end
>
> I've been using 30log for this purpose and it has a really nice abstraction for inheritance using objType:extend('new type') interface.
> https://github.com/Yonaba/30log/wiki/Subclasses
>
> Kind Regards,
> Ali Rezvani
> ------- Original Message -------
> On Sunday, November 5th, 2023 at 4:47 PM, Hans van der Meer <havdmeer@ziggo.nl> wrote:
>
>
> > I programmed some object classes (PIL 21 as guideline). What I could not find is how to call back from a subclass to a superclass.
> > The reason for my question:
> >
> > class A has subclasses Aa and Ab, all having a function f: A:f(x), Aa:f(x), Ab:f(x)
> >
> > both Aa and Ab have a large part of their code in common, I would like to keep the common code executed in the superclass A (as it will safeguard me from diverging adaptations to the code).
> > Therefore in Aa:f() and Ab:f()  the argument x is translated for each in a specific manner and should then passed upwards in the class heirarchy to A.
> > Thus an object Ab called should call back to A:f(x) with x the adapted value of x.
> > I hope I made myself clear.
> >
> >  It might be impossible what I have in mind, but I will gladly be informed then.
> >
> > yours sincerely
> > dr. Hans van der Meer
> >