Module expadom.class
Class module.
method __init will be called upon instantiation
single property:
readonly = boolean writeonly = boolean alias_to = string --> different prop name, if this is an alias. Alias will use its own get/set functions, but reads-from/writes-to other props location. set = function(self, value) -- return value to set or throws a HARD error self.__prop_values[prop_name] = value end get = function(self) -- return the value or throws a HARD error return self.__prop_values[prop_name] end
Functions
Class.create (name[, ancestor[, methods[, properties]]]) | creates a new class. |
Class.get_property_get (class, name) | returns the property-getter function. |
Class.get_property_set (class, name) | returns the property-setter function. |
Class.is_class (tbl) | Is the table a "Class". |
Class.is_instance_of (class, instance) | Is the table an instance of the given class. |
Class.is_readonly (class, name) | returns whther the property is read-only. |
Class.is_writeonly (class, name) | returns whther the property is write-only. |
Class.set_property_get (class, name, get) | sets the property-getter function for a property of a class. |
Class.set_property_set (class, name, set) | sets the property-setter function for a property of a class. |
Functions
- Class.create (name[, ancestor[, methods[, properties]]])
-
creates a new class.
Parameters:
- name
string
name of the class. Will be stored in field
__classname
. - ancestor class the class to inherit from (optional)
- methods table table with all methods (functions keyed by their name) (optional)
- properties table table with properties (property tables as defined above, keyed by their name) (optional)
Returns:
-
new class
- name
string
name of the class. Will be stored in field
- Class.get_property_get (class, name)
-
returns the property-getter function.
When overriding property-get functions in descendants, this can be used
to fetch the original function and call it.
Parameters:
- class class a class
- name string the property name
Returns:
-
the property-get function
Raises:
if class is not a class, or name is not a string - Class.get_property_set (class, name)
-
returns the property-setter function.
When overriding property-set functions in descendants, this can be used
to fetch the original function and call it.
Parameters:
- class class a class
- name string the property name
Returns:
-
the property-set function
Raises:
if class is not a class, or name is not a string - Class.is_class (tbl)
-
Is the table a "Class".
Checks whether a table is a class, not any speciifc type of class, just whether
it is a class from this class model/system.
Since it also returns a message if not a class, it can be used in assertions.
Parameters:
- tbl the table (or other types) to verify
Returns:
-
true if a class, or false+error otherwise
- Class.is_instance_of (class, instance)
-
Is the table an instance of the given class.
Since it also returns a message, it can be used in assertions.
Parameters:
- class the class
- instance the instance to verify for being an instance of class-'class'
Returns:
-
true if it is an instance of the class, or false+error otherwise
Raises:
if class is not a 'class'Usage:
local Cat = Class("Cat") local sylvester = Cat {name = "Sylvester"} assert(Class.is_instance_of(Cat, sylvester))
- Class.is_readonly (class, name)
-
returns whther the property is read-only.
Parameters:
- class class a class
- name string the property name
Returns:
-
boolean
Raises:
if class is not a class, or name is not a string - Class.is_writeonly (class, name)
-
returns whther the property is write-only.
Parameters:
- class class a class
- name string the property name
Returns:
-
boolean
Raises:
if class is not a class, or name is not a string - Class.set_property_get (class, name, get)
-
sets the property-getter function for a property of a class.
Parameters:
- class class a class
- name string the property name
- get function the property getter function
Returns:
-
true on success, nil+err if no property by that name exists
Raises:
if class is not a class,name
is not a string, orget
is not a function - Class.set_property_set (class, name, set)
-
sets the property-setter function for a property of a class.
Parameters:
- class class a class
- name string the property name
- set function the property setter function
Returns:
-
true on success, nil+err if no property by that name exists
Raises:
if class is not a class,name
is not a string, orset
is not a function