Created
June 30, 2024 06:30
-
-
Save GammaGames/ae5dd376fc0a5dad51542029fa1dd9ba to your computer and use it in GitHub Desktop.
Inheritance test for the Playdate SDK's object system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class("Parent").extends() | |
function Parent:foo() | |
print("parent-foo") | |
end | |
function Parent:bar() | |
print("parent-bar-1") | |
self:foo() | |
print("parent-bar-2") | |
end | |
class("Child").extends(Parent) | |
function Child:foo() | |
print("child-foo-1") | |
Child.super.foo(self) | |
print("child-foo-2") | |
end | |
function Child:bar() | |
print("child-bar-1") | |
Child.super.bar(self) | |
print("child-bar-2") | |
self:foo() | |
print("child-bar-3") | |
end | |
local c = Child() | |
c:bar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
child-bar-1 | |
parent-bar-1 | |
child-foo-1 | |
parent-foo | |
child-foo-2 | |
parent-bar-2 | |
child-bar-2 | |
child-foo-1 | |
parent-foo | |
child-foo-2 | |
child-bar-3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment