Module:Inheritance/doc
This is the documentation page for Module:Inheritance
Inheritance
editThis module contains a basic class together with an extend statement to inherit from existing classes. Thus it is intended for other Lua scripts and not to be invoked by wiki pages.
Please note that inheritance does only work with the basic class introduced and its subclasses.
Class
editBasic class with a constructor and (class) type checking.
With the extend
statement below you can inherit from this class and its subclasses.
You can create an instance of this class via:
local instance = Class();
Although this is possible at the moment consider the basic class to be abstract and instantiate inherited classes only.
Class:init
edit(Empty) Class constructor that gets called on instantiation by default. Overwrite this method to implement a custom constructor. Since it is empty there is no reason to call this basic constructor before if you do so.
Class:isa
editChecks if this object is an instance of a specific class.
Parameters:
- [
Class
] aClass: class the object is expected to be of
Returns: Returns true if the object is an instance of the class specified or any class derived from, returns false otherwise.
Class:super
editGetter for super class this class was derived from.
Returns: Super class if the class was derived from any class, nil otherwise.
extend
editThe extend statement allows to inherit from a class. It creates a basic class extending the class specified. Please note that inheritance does only work with the basic class introduced and its subclasses.
Example:
Statement usage
local i = require("inheritance"); local Person = i.extend(i.Class); -- function Person:init(name) self.name = name; end -- function Person:getName() return self.name; end
Class usage
local user = Person("Testy"); return user:getName();
Parameters:
- [
Class
] baseClass: class to be extended - must be Class or any class derived from Class
Returns: Returns a basic class extending the class specified. The new class inherits all methods and fields of the base class.