Class Module
See also: Classes
#class.new
class class.new()
class class.new(class baseClass)
Create a new class. If 'baseClass' is given, creates a child of it and set
the 'parent' variable to its base.
This will not call the constructor. That is what the __call operator
on the returned class is for: to create an instance of the class.
Example:
local myClass = class.new(); -- Creates the class 'myClass', but does not run it's constructor.
local inst = myClass(); -- Creates 'inst', an instance of 'myClass', and runs it's constructor.
#class.vector3d
vector3d class.vector3d()
vector3d class.vector3d(number x,
number y)
vector3d class.vector3d(number x,
number y, number z)
Create a new vector3d. If 'x', 'y' and 'z' are given, the new vector3d retains the
given values. Alternatively, you may also supply only 'x' and 'y', or nothing at all. Any
unspecified values will default to 0.0.
The vector3d class contains metamethods for operations such as vector scaling and dot product.
See also: Vector3d Class.
#class:is_a
boolean class:is_a(class baseClass)
Checks if this class is an instance of or child of the given 'baseClass'.
Returns true if so, otherwise returns false.
This is a method that all classes inherit, and not a function of the Class module. This means that you
should call this on your classes with the ':' operator rather than trying to call class.is_a() itself.
Example:
local Animal = class.new();
local Dog = Animal();
print(Dog:is_a(Animal)); -- This is valid
print(Dog.is_a(Animal)); -- Not valid; must use ':' to call
print(class.is_a(Dog)); -- Not valid; do not call class.is_a() directly
#Class Example
For a more in-depth example and explanation, please see the classes page.
Example:
-- Dog should be a child of Animal
Animal = class.new();
Dog = Animal();
-- Banana should be a child of fruit
Fruit = class.new();
Banana = Fruit();
print("Dog is an Animal?", Dog:is_a(Animal)); -- Should be true
print("Banana is a Fruit?", Banana:is_a(Fruit)); -- Should be true
print("Banana is an Animal?", Banana:is_a(Animal)); -- Should be false
Page last updated at 2018-09-25 20:47:13