Difference between revisions of "Class Module"

From SolarStrike wiki
Jump to: navigation, search
(Created page with "== 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 '''...")
 
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
See also: [[Classes]]
 +
 
== new ==
 
== new ==
 
'''class class.new([class baseclass])'''
 
'''class class.new([class baseclass])'''
Line 13: Line 15:
  
 
The vector3d class contains metamethods for operations such as vector scaling and dot product.
 
The vector3d class contains metamethods for operations such as vector scaling and dot product.
 +
 +
See also: [[Vector3d Class]]
 +
 +
 +
== is_a ==
 +
'''boolean class.is_a(class baseclass)'''
 +
 +
Checks if this class is an instance of of child of the given base class. Returns true if so, otherwise false.
 +
 +
 +
'''Example:'''
 +
<source lang="lua">
 +
-- 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
 +
</source>

Latest revision as of 21:13, 6 June 2018

See also: Classes

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.


vector3d

vector3d class.vector3d([number x, number y, number z])

Create a new table (class) of vector3d. If x, y and z are given, the new vector3d retains the given values.

The vector3d class contains metamethods for operations such as vector scaling and dot product.

See also: Vector3d Class


is_a

boolean class.is_a(class baseclass)

Checks if this class is an instance of of child of the given base class. Returns true if so, otherwise false.


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