Skip to content

Instantly share code, notes, and snippets.

@GammaGames
Created June 30, 2024 06:30
Show Gist options
  • Save GammaGames/ae5dd376fc0a5dad51542029fa1dd9ba to your computer and use it in GitHub Desktop.
Save GammaGames/ae5dd376fc0a5dad51542029fa1dd9ba to your computer and use it in GitHub Desktop.
Inheritance test for the Playdate SDK's object system
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()
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