LCS.class (args) |
Creates a class |
LCS.class.final (args) |
Creates a final class. |
LCS.class.static (args) |
Creates a static class. |
LCS.is_A (thing, kind) |
Checks if nature of the given argument 'thing'. |
[class] (args) |
Default class constructor used to instantiation. |
[class]:extends (args) |
Returns a new class derived from class [class]. |
[class]:getClass () |
Checks for a reference to the superclass of class [class] |
[class]:getSubClasses () |
Checks for a list of all classes deriving from class [class] |
[class]:new (args) |
Default class constructor used to instantiation. |
[class]:super (method, ...) |
Calls a method defined in a parent of class [class] |
[instance]:getClass () |
Checks for the reference to the class from which 'instance' was created |
[instance]:is_A (aClass) |
Checks if instance [instance] was instantiated from a specific class. |
[instance]:super (method, ...) |
Calls a methods defined in a parent of a class from which object 'instance' was created |
- LCS.class (args)
-
Creates a class
Parameters
-
args: [table] Optional.A key-index table to be the class members.
Usage:
LCS = require('LCS')
Vector = LCS.class { x = 0, y = 0}
Return value:
[table] A class
- LCS.class.final (args)
-
Creates a final class. They do not offer support for inheritance. So these classes cannot be derived.
Parameters
-
args: [table] Optional.A key-index table to be the class members.
Usage:
LCS = require('LCS')
myFinalClass = LCS.class.final()
Return value:
[table] A final class
- LCS.class.static (args)
-
Creates a static class. These classes cannot instantiate objects.
Parameters
-
args: [table] Optional.A key-index table to be the class members.
Usage:
LCS = require('LCS')
myStaticClass = LCS.class.static()
Return value:
[table] A static class
- LCS.is_A (thing, kind)
-
Checks if nature of the given argument 'thing'.
Parameters
-
thing: [table] The reference holding a supposed object or a supposed class to be tested
-
kind: [string] Optional. A string value to be either 'object' or 'class'. When not given, returns a string representing the nature of the given 'thing'
Usage:
LCS = require('LCS')
myClass = LCS.class()
myObject = myClass()
print(LCS.is_A(myClass,'class')) --> True
print(LCS.is_A(myObject,'object')) --> True
print(LCS.is_A(myClass)) --> 'class'
print(LCS.is_A(myObject)) --> 'object'
Return value:
[boolean] or [string] True if 'thing' matches string 'kind', or the string 'object' or 'class'
- [class] (args)
-
Default class constructor used to instantiation. Similar to [class]:new(). Assumes the calling class is not static.
Parameters
-
args: [table] Optional.A list of arguments in a specific order to init the new instance. Using args assumes the constructor [class]:init() have been implemented upon class definition.
Usage:
LCS = require('LCS')
Vector = LCS.class {x = 0, y = 0}
function Vector:init(x,y)
self.x = x
self.y = y
end
v1 = Vector(1,2)
print(v1.x,v1.y) --> 1,2
Return value:
[table] An instance of class [class]
See also:
- [class]:extends (args)
-
Returns a new class derived from class [class]. Assumes class [class] is not a final class.
Parameters
-
args: [table] Optional. A key-index table to be the class members.
Usage:
LCS = require('LCS')
Animal = LCS.class()
function Animal:yell()
print('Yelling!')
end
Dog = Animal:extends {name = nil}
function Dog:init(name)
self.name = name
end
puppet = Dog('waffles')
print(puppet.name) --> waffles
puppet:yell() --> Yelling!
Return value:
[table] A new class which inherits from class [class]
See also:
- [class]:getClass ()
-
Checks for a reference to the superclass of class [class]
Usage:
LCS = require('LCS')
Animal = LCS.class()
Dog = Animal:extends {name = nil}
print(Dog:getClass() == Animal) --> True
Return value:
[table] or [nil] Returns a reference to the superclass of class [class]. If [class] does not derives from a class, returns nil
See also:
- [class]:getSubClasses ()
-
Checks for a list of all classes deriving from class [class]
Usage:
LCS = require('LCS')
Animal = LCS.class()
Dog = Animal:extends {name = nil}
list = Animal:getSubClasses()
for i,class in ipairs(list) do
if class == Dog then print('True') end
end --> True
Return value:
[table] Returns an array list of all classes deriving from class [class]
- [class]:new (args)
-
Default class constructor used to instantiation. Similar to [class](). Assumes the calling class is not static.
Parameters
-
args: [table] Optional.A list of arguments in a specific order to init the new instance. Using args assumes the constructor [class]:init() have been implemented upon class definition.
Usage:
LCS = require('LCS')
Vector = LCS.class {x = 0, y = 0}
function Vector:init(x,y)
self.x = x
self.y = y
end
v1 = Vector:new(3,4)
print(v1.x,v1.y) --> 3,4
Return value:
[table] An instance of class [class]
See also:
- [class]:super (method, ...)
-
Calls a method defined in a parent of class [class]
Parameters
-
method: [string] A string refferring to the name of the function to be invoked.
-
...: Optional. The required arguments which will be passed to the method called, in proper order.
Usage:
LCS = require('LCS')
Dog = LCS.class {name = ''}
function Dog:init(name)
self.name = name
end
SuperDog = Dog:extends {power = 0}
function SuperDog:init(name,power)
self:super('init',name)
self.power = power
end
superPuppet = SuperDog('superPuppet',100)
print(superPuppet.name) --> superPuppet
print(superPuppet.power) --> 100
Return value:
[...] The result of expected from the method call.
See also:
- [instance]:getClass ()
-
Checks for the reference to the class from which 'instance' was created
Usage:
LCS = require('LCS')
Animal = LCS.class()
Dog = Animal:extends {name = nil}
puppet = Dog()
print(puppet:getClass() == Dog) --> True
Return value:
[table] Returns a reference tto the class from which 'instance' was created
See also:
- [instance]:is_A (aClass)
-
Checks if instance [instance] was instantiated from a specific class. This lethod should not be called from a class.
Parameters
-
aClass: [table] Optional. When given, tests if 'instance' was instantiated from aClass.
Usage:
LCS = require('LCS')
Animal = LCS.class()
thing = Animal()
print(thing:is_A(Animal)) --> True
print(thing:is_A() == Animal)--> True
Return value:
[boolean] or [table] Returns True if 'instance' was instantiated from aClass, either False. If 'aClass' is not given, returns a reference to the class from which 'instance' was created.
See also:
- [instance]:super (method, ...)
-
Calls a methods defined in a parent of a class from which object 'instance' was created
Parameters
-
method: [string] A string refferring to the name of the function to be invoked.
-
...: Optional. The required arguments which will be passed to the method called, in proper order.
Usage:
LCS = require('LCS')
Dog = LCS.class {name = ''}
function Dog:init(name)
self.name = name
end
function Dog:say(something)
print(something)
end
SuperDog = Dog:extends {power = 0}
function SuperDog:say(something)
print('Superdog says : '..something)
end
superPuppet = SuperDog()
superPuppet:say('Hello!') --> SuperDog says : Hello!
superPuppet:super('say','Hello!') --> Hello!
Return value:
[...] The result of expected from the method call.
See also: