Conversion Methods - brombres/Rogue GitHub Wiki
Syntax
class Type1
METHODS
method to->Type2
return Type2(...)
method to->Type2(param1:Type1,...)
if (param1) return Type2(...)
...
endClass
class Type2
METHODS
method init( value:Type1 )
...
endClass
Description
When the conversion command value->Type2 is given, and value is of type Type1, the conversion happens using the first available mechanism from the following list:
- If Type1 and Type2 are the same type, no conversion is performed.
- If Type1 and Type2 are both primitives, a built-in primitive conversion is used.
- If Type1 has a method
to->Type2, that method is called. - If Type2 has a constructor that accepts an arg of
Type1, a Type2 object is created utilizing that constructor. - If both types are reference types and Type1 is
instanceOfType2, a widening cast is used to change the reference type without changing the object data.
Conversion methods with parameters are only invoked when args are specified, e.g. obj->Type(arg1,arg2).