API
Last Updated: 2009-01-31 for 1.0.0
Class Methods
<class>:Extend()
Defines a new subclass by extending this class.
The new subclass will inherit any properties and methods defined on this
class or any of its superclasses (including the base class), and will also
provide a "prototype" table on which properties and methods may be defined
that will be inherited by all objects of the class or its subclasses.
This method may be overridden. An implementor overriding this method must return the result of self:Super("Extend") in order to provide the caller a usable subclass reference. Returning "false" or raising an error may suggest to the caller that this class should not be extended, but Lua's flexibility makes strict restrictions impossible to enforce. A caller in doubt may verify that the returned value is a valid class reference with, for example, LibOOP:SubClassOf(<return>).
Return value
A table representing the newly created subclass.
<class>:GetSuperClass()
Returns the superclass of this class.
Equivalent to LibOOP:GetSuperClass(<class>).
This method may not be overridden.
Return value
A reference to the table representing the class' superclass, or false if the class has no superclass.
<class>:New()
Instantiates (creates a new object of) this class.
The new object will inherit any properties and methods defined on this
class' or any superclass' prototype, including the methods "Clone",
"GetClass", "InstanceOf" and "Super" from the base prototype.
This method may be overridden, for example to implement a constructor. An implementor overriding this method must return the result of self:Super("New") in order to provide the caller a usable object reference. It is also permissible to return a reference to an existing instance of the class, for example to implement a singleton pattern. Returning "false" or raising an error may suggest to the caller that this class should not be instantiated, but Lua's flexibility makes strict restrictions impossible to enforce. A caller in doubt may verify that the returned value is a valid object reference with, for example, LibOOP:InstanceOf(<return>).
Return value
A table representing the newly created object.
<class>:SubClassOf(super, direct)
Tests if this class extends a given superclass.
If "super" is omitted, this always returns true (when called on a LibOOP
class). If "direct" is true, then "class" must extend "super" directly;
otherwise, it may also extend a subclass of "super". Equivalent to
LibOOP:SubClassOf(<class>[, <super>[, <direct>]]).
This method may not be overridden.
Parameters
- super
- (Optional) A class reference to test inheritence from.
- direct
- (Optional) If true, tests only direct inheritence.
Return value
True if the class satisfies the specified inheritence profile, false otherwise.
<class>:Super(method, ...)
Calls the inherited version of the given method.
The method will be called like a normal class method, passing this class as
the implicit first argument "self" (even though the method was defined on a
superclass of this class). However, the method will still have the scope
(and the variables in closure) with which it was defined, rather than that
of this class.
This method may not be overridden.
Parameters
- method
- The name of the inherited method to be called, as a string.
- ...
- (Optional) Any number of arguments to pass to the method.
Return value
All return values from the method.
Object Methods
<object>:Clone(...)
Clones this object.
This is equivalent to calling this object's class' :New() method to create
a new instance of the class (using any provided arguments), and then
performing a shallow copy of this object's properties onto the clone.
This method may be overridden. An implementor overriding this method must return the result of self:Super("Clone", ...) or (self:GetClass()):New(...) with appropriate arguments in order to provide the caller a usable object reference. Returning "false" or raising an error may suggest to the caller that instances of this class should not be cloned, but Lua's flexibility makes strict restrictions impossible to enforce. A caller in doubt may verify that the returned value is a valid object reference with, for example, LibOOP:InstanceOf(<return>).
Parameters
- ...
- (Optional) Any number of arguments to pass to the clone's constructor.
Return value
A table representing the newly created object.
<object>:GetClass()
Returns the class of this object.
Equivalent to LibOOP:GetClass(<object>).
This method may not be overridden.
Return value
A reference to the table representing the object's class.
<object>:InstanceOf(class, direct)
Tests if this object is an instance of a given class.
If "class" is omitted, this always returns true (when called on a LibOOP
class instance). If "direct" is true, then "object" must be an instance of
"class" itself; otherwise, it may also be an instance of a subclass of
"class". Equivalent to
LibOOP:InstanceOf(<object>[, <class>[, <direct>]]).
This method may not be overridden.
Parameters
- class
- (Optional) A class reference to test instantiation from.
- direct
- (Optional) If true, tests only direct inheritence.
Return value
True if the object satisfies the specified inheritence profile, false otherwise.
<object>:Super(method, ...)
Calls the inherited version of the given method.
The method will be called like a normal object method, passing this object
as the implicit first argument "self". However, the method will still have
the scope (and the variables in closure) with which it was defined, rather
than that of this object's class or prototype.
This method may not be overridden.
Parameters
- method
- The name of the inherited method to be called, as a string.
- ...
- (Optional) Any number of arguments to pass to the method.
Return value
All return values from the method.
Library Methods
LibOOP:Class()
Defines a new class.
The new class will inherit the methods "New", "Extend", "GetSuperClass",
"SubClassOf" and "Super" from the base class, and will also provide a
"prototype" table on which properties and methods may be defined that will
be inherited by all objects of the class or its subclasses.
Return value
A table representing the newly created class.
LibOOP:GetClass(object)
Determines if the given reference is an object, and returns its class.
If the argument is a valid LibOOP class instance, this is equivalent to
<object>:GetClass().
Parameters
- object
- A (potential) object reference to get the class of.
Return value
A reference to the table representing the object's class, or nil if called on a non-object.
LibOOP:GetSuperClass(class)
Determines if the given reference is a class, and returns its superclass.
If the argument is a valid LibOOP class, this is equivalent to
<class>:GetSuperClass().
Parameters
- class
- A (potential) class reference to get the superclass of.
Return value
A reference to the table representing the class' superclass, false if the class has no superclass, or nil if called on a non-class.
LibOOP:InstanceOf(object, class, direct)
Determines if the given reference is an instance of a given class.
If "class" is omitted, this returns true if "object" is a valid LibOOP
class instance. If "class" is provided and "direct" is true, then "object
must be an instance of "class" itself; otherwise, it may also be an
instance of a subclass of "class". If "object" is a valid LibOOP class
instance, this is equivalent to
<object>:InstanceOf(<class>[, <direct>]).
Parameters
- object
- A (potential) object reference to test the inheritance of.
- class
- (Optional) A class reference to test instantiation from.
- direct
- (Optional) If true, tests only direct inheritence.
Return value
True if the object satisfies the specified inheritence profile, false if it doesn't, or nil if called on a non-object.
LibOOP:SubClassOf(class, super, direct)
Determines if the given reference is a subclass of a given superclass.
If "super" is omitted, this returns true if "class" is a valid LibOOP
class. If "super" is provided and "direct" is true, then "class" must
extend "super" directly; otherwise, it may also extend a subclass of
"super". If "class" is a valid LibOOP class, this is equivalent to
<class>:SubClassOf(<super>[, <direct>]).
Parameters
- class
- A (potential) class reference to test the inheritance of.
- super
- (Optional) A class reference to test inheritence from.
- direct
- (Optional) If true, tests only direct inheritence.
Return value
True if the class satisfies the specified inheritence profile, false if it doesn't, or nil if called on a non-class.
LibOOP:Super(ref, method, ...)
Calls the inherited version of the given method.
If the reference is a class or object, this is equivalent to
<ref>:Super(method[, ...]); otherwise, this does nothing and returns
nothing.
Parameters
- ref
- A class or object reference on which to operate.
- method
- The name of the inherited method to be called, as a string.
- ...
- (Optional) Any number of arguments to pass to the method.
Return value
All return values from the method.
Last Updated: 2009-01-31 for 1.0.0
Comments