Dynamic value casting

Kutululu supports dynamic casting of values. Together with rich type definitions this creates powerfull feature.

Casting can be performad at the moment of program execution (dynamically), when the actual value of the casted variable is known. This allows us to recognize and cast different data types to objects we want to use.

Application can use casting functions defined in plugins or added to system, so it can be expanded in the future to support new data formats and functions.

It is for example possible to try to cast any file to raster type. This conversion will convert PNG, JPG or BMP format to raster structure, that may be displayed on display. If some other format is specified in future, it may be used too.

Value is not supposed to loose any information when casted - explicit function defining how the casted value is to be processed must be used.

Explicit casting

Explicit casting may be performed using {value} as {type} syntax.

Implicit casting

Kutululu will try to cast the value to appropriate type as necessary:

Chained casting

When there is no direct cast, Kutululu will try to find a chain of casts, that will allow the casting to be done.

For example you may cast some binary data to sound. The data is in WAV format (http://en.wikipedia.org/wiki/Wav). WAV format itself is variant of RIFF format (http://en.wikipedia.org/wiki/Resource_Interchange_File_Format).

Thus following chain of casts will be created:

{d:data like 'RIFF'} -> iff {d:iff where type='WAVE'} -> sound

Defining custom cast function

It is possible to define custom casting function. Casting function must be named cast and take exactly one argument and return it casted to type specified in result type. The specification of source and resulting type must be as detailed as possible.

func cast {v:src_type} -> res_type

See how casting functions are defined in system.raster module.