Skip to content

Instantly share code, notes, and snippets.

@RonJeffries
Created October 3, 2014 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RonJeffries/6e0e3856a27dc3b20b5a to your computer and use it in GitHub Desktop.
Save RonJeffries/6e0e3856a27dc3b20b5a to your computer and use it in GitHub Desktop.
Superclass / subclass
--# 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