OOP - Multiple inheritance chain error

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

OOP - Multiple inheritance chain error

Post by ddabrahim »

Hi all!

I'm trying to use an OOP library to help me organise my code better but it seems all OOP library I can find is limited in how many classes you can chain. Usually if I try to chain more than 2 classes, I get an error, the most common one is:

Error: [love "boot.lua"]:48: Failed to initialize filesystem: already initialized

One of the libraries I tried was Classic, I have reported the error on GitHub but received no reply not only for Classic but for none of the libraries I tried and have similar error.

Here is the GitHub link to the issue for Classic with an example posted that reproduce the problem:
https://github.com/rxi/classic/issues/23

Could someone please have a look and see if its a limitation of the Library or is it my code or else?
Is there any solution to this

I would appreciate any help.

Also if you know any good OOP library I am open to recommendations.

Thank you.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: OOP - Multiple inheritance chain error

Post by pgimeno »

There are two problems here.

One is that the error you're getting is not meaningful, I don't know why. The error I get with your test zipfile is a stack overflow.

(Edited and then undone the edit)

The other is that you should use <ClassName>.super.new(self, ...) to call the super of a class, not self.super.new. See the example in the readme:

Code: Select all

function Rect:new(x, y, width, height)
  Rect.super.new(self, x, y)
  self.width = width or 0
  self.height = height or 0
end
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: OOP - Multiple inheritance chain error

Post by ReFreezed »

To add to what pgimeno said, the reason you shouldn't call self.super.new is because it always refer to the same actual function because 'self' and 'self.super' always refer to the same values (i.e. you'll recursively call the same function, eventually resulting in a stack overflow).
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: OOP - Multiple inheritance chain error

Post by ddabrahim »

Thank you!

So it was my mistake. I did not pay attention to that I am supposed to be using the class name. I believed within the constructor function 'self' is going to refer to the class.

Thanks a lot for the explanation. Really appreciate it!
Post Reply

Who is online

Users browsing this forum: baconhawka7x and 47 guests