ICI Modules: utype: def


Modules by name : by type

Synopsis

utype = utype.def(string [, func [, func [, func]]])

Description

Define a new type with the given name. If no other arguments are passed the type behaves as a normal struct object, i.e, it is a dictionary that stores some number of key/value pairs.

The function arguments are as follows. The first is the new function, called when a new instance of the object is created and used to construct the new instace. The second is the assign function and is called when attempts are made to assign into the struct. Finally, the third is the fetch function and is used when the struct is read.

The new function is called with two arguments, the first is the new instance and the second an array of the extra arguments to utype.new. Any result is ignored.

The assign function is called with three arguments, the first an instance of the type, the second the key being assigned to, and the third the value being assigned. Any result is ignored however errors are propogated as would be expected.

The fetch function is called with two arguments, an instance of the type and a key being fetched. The result of the function is the value at that key.

A utype object may be indexed using the keys "new", "assign" and "fetch" to retrieve or set the corresponding functions.