Module bound_object
Some weird meta stuff that lets us create a nice object oriented interface around the C bindings.
This is mostly used internally, but the init hook is useful for custom objects.
BoundObject extends Object
Properties
| real | The userdata that represents an instance inside of the game engine. |
Class Methods
| BoundObject:new (...) | Create a new instance of BoundObject. |
Configuration
| lib | The Lua library provided by the game engine that instance method calls are forwarded to. |
| _collections | A table of collection configurations for the class. |
Hooks
| realize (self, ...) | Responsible for interacting with the lib and returning a userdata. |
| init (self, ...) | Called immediately after realize . |
Helpers
| BoundObject.fwd_func (name) | Generate a method that performs one-to-one argument forwarding to lib |
| BoundObject.fwd_func_real (name) | Generate a method that performs one-to-one argument forwarding,
replacing each argument with arg.real |
| BoundObject.fwd_func_opts (name, keys, defaults) | Generate a method that performs key-mapped argument forwarding. |
| BoundObject.fwd_adder (name) | Generate a lib forwarded method intended to add an object to a collection. |
| BoundObject.fwd_remover (name) | Generate a lib forwarded method intended to remove an object from a collection. |
| BoundObject.fwd_zeroing_setter (fname, pname) | Generate a lib forwarded setter that enables the corresponding
property to be set to nil by the game engine. |
| BoundObject.readonly () | A function that throws a "read only" error, intended for setter forwarding. |
Properties
Properties. Significant fields on an instance.Class Methods
Class Methods. Must be called onClass, with a capital leading character.
e.g. Class:method("foo")
- BoundObject:new (...)
-
Create a new instance of
BoundObject.This is the external method used to create a bound object. It calls the realize hook, then the init hook.
newshould not be overloaded by a subclass. Implement the init hook if you want to perform actions when the object is created.Parameters:
Returns:
-
BoundObject
A new instance of
BoundObject
Configuration
Configuration. Required by subclass declarations. Used when instantiating concrete subclasses.- lib
- The Lua library provided by the game engine that instance method calls are forwarded to.
- _collections
- A table of collection configurations for the class.
Hooks
Hooks. Callbacks implemented in subclasses to customize behavior. Hooks are called on individual instances.- realize (self, ...)
-
Responsible for interacting with the lib and returning a userdata.
This hook is required. A
BoundObjectwill not function without an implementation of realize .Parameters:
- self BoundObject An instance in the throws of instantiation
- ... Any arguments passed to new
Returns:
-
userdata
The userdata that will be set to real
- init (self, ...)
-
Called immediately after realize .
This is only called once in the
BoundObject's lifecycle.Parameters:
- self BoundObject The realized instance
- ... Any arguments passed to new
Helpers
Helpers. Utility functions stored on a class. Called using dot syntax. e.g.Class.helper("foo")
- BoundObject.fwd_func (name)
-
Generate a method that performs one-to-one argument forwarding
to lib
Parameters:
Returns:
-
function
- BoundObject.fwd_func_real (name)
-
Generate a method that performs one-to-one argument forwarding,
replacing each argument with
arg.realParameters:
Returns:
-
function
- BoundObject.fwd_func_opts (name, keys, defaults)
-
Generate a method that performs key-mapped argument forwarding.
This will generate a method that accepts one argument, an
optstable.The values of the
optstable are sent to the lib function specified byname. They are arranged in the order that the table keys appear in thekeyslist. Any keys not specified in thekeyslist are ignored.Parameters:
- name string The name of the lib function
- keys table The ordered list of keys to be mapped to the lib function
- defaults table An optional defaults table
Returns:
-
function
- BoundObject.fwd_adder (name)
-
Generate a lib forwarded method intended to add an object to a
collection.
This performs some caching in the Lua VM so added objects don't get collected by the GC.
Parameters:
Returns:
-
function
- BoundObject.fwd_remover (name)
-
Generate a lib forwarded method intended to remove an object from a
collection.
This performs some caching in the Lua VM so removed objects can get collected by the GC.
Parameters:
Returns:
-
function
- BoundObject.fwd_zeroing_setter (fname, pname)
-
Generate a lib forwarded setter that enables the corresponding
property to be set to
nilby the game engine.This implements an ad-hoc hook called
_zerowhich is called by the engine when the object has been destroyed. An example of this behavior is how a ${music|Music} instance is destroyed when it is finished playing.Parameters:
Returns:
-
function
- BoundObject.readonly ()
-
A function that throws a "read only" error, intended for
setter forwarding.
Returns:
-
function