IExpando interface

To enable dynamic programming with a map-based implementation, Gosu provides the IExpando interface, which contains the following method and property declarations. Any class that implements this interface can behave as an expando object in the context of a variable declared as the Dynamic type.

The base configuration provides the Expando class, which is an implementation of this interface.

Get field value

override function getFieldValue(s: String): Object

The getFieldValue method gets a field and returns an Object.

Set field value

override function setFieldValue(s: String, o: Object)

The setFieldValue method sets a field with an Object.

Invoke method

override function invoke(s: String, objects: Object[]): Object

The invoke method invokes a method with zero, one, or more arguments passed as an array.

Set default field value

override function setDefaultFieldValue(s: String)

The setDefaultFieldValue method sets a field default value. Gosu calls this method in certain cases where Gosu code tries to get an uninitialized field value. The only situation where Gosu calls the method is during automatic creation of intermediary objects in an object path. For example:

var dyn = new Dynamic()
dyn.abc.def = "hi"
print( dyn.abc.def ) // prints "hi"

In this example, note the middle line. Because the dyn.abc property does not exist yet, and it is necessary to set the abc.def property, Gosu creates the intermediate object. During this automatic creation process, Gosu calls the setDefaultFieldValue to create the default value for abc. In the built-in Expando implementation, this method always creates another instance of the Expando class.

See also