olua.lib
Class Object

olua.lib.Object

I am the base class for all Objective Lua classes.
Static Method Summary
+ addClassMethodCategory: categoryname withTemplate: template andMetadata: metadata
Adds class methods to a class.
+ addObjectMethodCategory: categoryname withTemplate: template andMetadata: metadata
Adds object methods to a class.
+ alloc
Create a new object.
+ createSubclassNamed: name
Creates a new subclass of this class.
+ hash
Returns a hash code for the class.
+ methodMetadata
Returns the table of method metadata for this class.
+ methodTemplates
Returns the table of method templates for this class.
+ name
Returns the name of this class.
+ superclass
Returns the class' superclass.
+ toString
Returns a string representing this class.
Constructor Summary
- init
Initialises a new instance of the object.
Method Summary
- class
Returns the object's class.
- forwardInvocation: message
Called when an unrecognised message is sent to this object.
- hash
Returns a hash code for the object.
- operatorConcatenate: other
Called on .. operator.
- operatorIndex: key
Called when an recognised table key is accessed on the object.
- performSelector: selector
Call a method on the object.
- performSelector: selector withArgs: args
Call a method on the object.
- respondsToSelector: selector
Tests whether this object responds to a particular selector.
- superclass
Returns the object's superclass.
Method Detail

+ addClassMethodCategory: categoryname withTemplate: template andMetadata: metadata

Adds class methods to a class.

Do not use this method --- it is intended for use by the runtime only.

The specified template containing class methods is added to the class. (In the current implementation, the template is executed immediately and the category name discarded.)

See +methodTemplates for information on templates. See +methodMetadata for information on metadata.

Parameters:
categoryname - the name of the category
template - the method template
metadata - the metadata table for these methods

+ addObjectMethodCategory: categoryname withTemplate: template andMetadata: metadata

Adds object methods to a class.

Do not use this method --- it is intended for use by the runtime only.

The specified template containing object methods is added to the class. (In the current implementation, the template is added to the class' template table and executed on object instantiation.)

See +methodTemplates for information on templates.

Parameters:
categoryname - the name of the category
template - the method template
metadata - the metadata table for these methods

+ alloc

Create a new object.

This method creates an instance of the class. Any code in the class' statics blocks will be run, but no constructor methods will be. Normally an init method will then be called on the new returned object.

Returns:
the new object

+ createSubclassNamed: name

Creates a new subclass of this class.

Do not use this method --- it is intended for use by the runtime only.

A new class is created as a subclass of this one, with its internal name field set to the specified value. The class has +superclass, +name, +methodTemplates and +hash methods predefined, but no others.

Parameters:
name - the name of the new class
Returns:
the new class object

+ hash

Returns a hash code for the class.

The hash code is a unique integer identifying the class. It is guaranteed never to be reused. Note that the hash code is not the same as the Lua internal hash.

Returns:
the hash code

+ methodMetadata

Returns the table of method metadata for this class.

Do not use this method --- it is intended for use by the runtime only.

This method returns the table of method metadata objects for the class. The table is keyed by selector (including the initial + or -). Each item is a table describing an individual method:

The absence of a method in the metadata table should not be considered indicative of the absence of the method! In Objective Lua, any method call may perform work, even if the runtime has defined no method of that name.

Type annotations consist of a list of tokens from the type annotation. Each token is a string. (String tokens contain the quotes.) If the argument had no type annotation, the list is empty.

Returns:
the metadata table

+ methodTemplates

Returns the table of method templates for this class.

Do not use this method --- it is intended for use by the runtime only.

This method returns the table of method templates for the class. The table is keyed by category name, with the default category having value 1.

Each template is a function with prototype:

function template(self, superclass, class)

When executed, the function adds methods to the table self; superclass and class are the superclass and class objects respectively.

Returns:
the method table

+ name

Returns the name of this class.

Returns:
a string

+ superclass

Returns the class' superclass.

Returns:
the superclass class object

+ toString

Returns a string representing this class.

By default, this is [classname class@hashcode] where classname is the name of the class and hashcode is a unique id.

Returns:
the string identifier

- class

Returns the object's class.

Returns:
the class object

- forwardInvocation: message

Called when an unrecognised message is sent to this object.

If a message is sent to the object, and there are no methods that implement it, the runtime will pass the message to this method. The object may then do whatever it wishes with it. The default behaviour is to throw a olua.lib.UnhandledMessageException; if the method instead returns, the return value will be returned from the original method.

Parameters:
message - the unrecognised message
Returns:
whatever the message should return

- hash

Returns a hash code for the object.

The hash code is a unique integer identifying the object. It is guaranteed never to be reused. Note that the hash code is not the same as the Lua internal hash.

Returns:
the hash code

- init

Initialises a new instance of the object.

All constructors must, eventually, call this.

Returns:
the receiver

- isKindOfClass: class

Tests whether this object inherits from a particular class.

This method returns true if the object is an instance of class, or of any subclass inheriting from class.

Parameters:
class - the class to test against
Returns:
true or false

- isProxy

Indicates whether this object is a proxy.

Proxies forward their methods on elsewhere; this method can be used to test for this (so that we know not to trust the class hierarchy, for example).

Returns:
true or false

- operatorConcatenate: other

Called on .. operator.

By default, this method performs:

return tostring(self) .. tostring(other)

Parameters:
other - the second operator argument
Returns:
the result

- operatorIndex: key

Called when an recognised table key is accessed on the object.

Don't override this unless you really know what you're doing; the default implementation in olua.lib.Object is required to make -forwardInvocation: and olua.lib.UnhandledMessageException work. For most purposes, overriding -forwardInvocation: is the right thing to do.

Parameters:
key - table key accessed
Returns:
the value of the key (normally a method)

- performSelector: selector

Call a method on the object.

The given no-argument selector is called on the object.

Parameters:
selector - the (mangled) selector
Returns:
whatever the method returns

- performSelector: selector withArgs: args

Call a method on the object.

The given selector is called on the object using the supplied arguments.

Parameters:
selector - the (mangled) selector
args - an array of arguments
Returns:
whatever the method returns

- respondsToSelector: selector

Tests whether this object responds to a particular selector.

Any class which overrides -forwardInvocation: to do special behaviour should override this.

Parameters:
selector - the (mangled) selector
Returns:
true or false

- superclass

Returns the object's superclass.

Returns:
the superclass class object

- toString

Returns a string representing this class.

By default, this is [classname@hashcode] where classname is the name of the object's class and hashcode is a unique id.

Returns:
the string identifier