Returns only the class, not in instance of it!
Init by classname(), which returns an Instance of the class!
require 'class'
-- definition of classes, "a" beeing the required self reference
Animal = class(function(a,name)
a.name = name
end)
function Animal:__tostring()
return self.name..': '..self:speak()
end
Cat = class(Animal, function(c,name,breed)
Animal.init(c,name) -- must init base!
c.breed = breed
end)
function Cat:speak()
return 'meow'
end
Lion = class(Cat)
function Lion:speak()
return 'roar'
end
-- init of class
local BigCat = Lion('Leo', 'African')
print(Leo)
--- "Leo: roar"
print(BigCat:is_a(Cat))
--- "true"