Skip to content

feat: add super() implementation#6990

Open
ElectricalBoy wants to merge 16 commits intomainfrom
baseclass-super
Open

feat: add super() implementation#6990
ElectricalBoy wants to merge 16 commits intomainfrom
baseclass-super

Conversation

@ElectricalBoy
Copy link
Collaborator

Summary

This PR adds BaseClass.super().

How did you test this change?

included tests

Copy link
Collaborator

@hjpalpha hjpalpha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the perf implications of this?

@ElectricalBoy
Copy link
Collaborator Author

what are the perf implications of this?

negligible: see leagueoflegends:User:ElectricalBoy/Sandbox/PerfTest1 and leagueoflegends:User:ElectricalBoy/Sandbox/PerfTest2

@mbergen
Copy link
Collaborator

mbergen commented Jan 22, 2026

What's the usecase for this?
In case of single level inheritance like in the linked PR, you imported the Base anways, and could do

function Child:fun()
    return Base.fun(self)
end

to call an overridden function of the Base, right?

@ElectricalBoy
Copy link
Collaborator Author

What's the usecase for this? In case of single level inheritance like in the linked PR, you imported the Base anways, and could do

function Child:fun()
    return Base.fun(self)
end

to call an overridden function of the Base, right?

function Child:fun()
	return self:super():fun()
end

I think that this is more readable as it clearly shows with super that the method of parent class is called; I mean, it's a widely used keyword in OOP already.
Also, I think Base.fun(self) really is a workaround for absense of super in our Class implementation

@Rathoz
Copy link
Collaborator

Rathoz commented Feb 2, 2026

Same as Salt, don't understand why this is needed? Other than maybe this?

instance.super = instance._base

@ElectricalBoy
Copy link
Collaborator Author

ElectricalBoy commented Feb 3, 2026

Same as Salt, don't understand why this is needed? Other than maybe this?

instance.super = instance._base

by our coding convention, anything starting with an underscore is considered private, so instance._base is bad in the first place

also, because _base is a class table, we cannot use : shorthand to call super methods in context of the current instance, i.e., instance.super:fun() is invalid and instance.super.fun(instance) is needed for it to work. Then again, self:super():fun() is just cleaner & more readable

@mbergen
Copy link
Collaborator

mbergen commented Feb 3, 2026

The issue i have with this is that it introduces a lot of code for very little gain.
Especially since it only supports single-level inheritance, no super():super() or similar.

Also self:super():fun() is questionable anyways, its not really clear what the content self in fun would be. I'd prefer the verbose style where you have to be obvious what gets passed instead of self.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants