-
-
Save RonJeffries/6e0e3856a27dc3b20b5a to your computer and use it in GitHub Desktop.
Superclass / subclass
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 | |
Class = class(Superclass) | |
function Class:init(x) | |
Superclass.init(self,x) | |
end | |
function Class:inClass() | |
return true | |
end | |
--# Main | |
-- Supers | |
function setup() | |
c = Class("class") | |
s = Superclass("superclass") | |
print("c:inClass") | |
c:inClass() -- works ok | |
print("s:inSuper") | |
s:inSuper() -- works ok | |
print("c:inSuper") | |
c:inSuper() -- does not work: error in Class line 9, inSuper is nil | |
end | |
function draw() | |
end | |
--# Superclass | |
Superclass = class() | |
function Superclass:init(name) | |
self.name = name | |
end | |
function Superclass:inSuper() | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment