EnglishРусский  
The project is closed! You can look at a new scripting language. It is available on GitHub.
Also, try our open source cross-platform automation software.

Ads

Installer and installation software
Commercial and Freeware installers.

Method declaration: method

You can define different methods for any types. Any method is a function associated with an object of the appropriate type, that the method should operate on. A method is defined by specifying the keyword method followed by the name of the return type (if it is required), an object type and a method name followed by a separating period. Like declaring a function, you should specify method parameters followed by its body: object.methodname( parameters ).

The parameter this is created automatically within the method; furthermore, this parameter contains the object to which the given method is called. The parameter this has the same type as the object does.

method uint str.islast( uint ch )
{
    return this[ *this - 1 ] == ch 
}

func main<main>  
{
   str mystr
   ...
   if mystr.islast('\')
   {
      ...
   }
}

You can specify result and alias attributes for method like for functions. Methods are responsible for object initialization and destruction, getting index and type conversion as well as for other operations. See more details on the System type methods page.

Type conversion

Type conversion is also declared with the help of the methods. A source type is specified as the object type of the method and a destination type of the object is specified as the method name. If the destination type is structured you must use result attribute.

// uint -> str
method str uint.str < result > 
{
   result.out4( "%u", this )
}

// str -> uint
method uint str.uint
{
   uint end
   return strtoul( this.ptr(), &end, 0 )
}

func main<main>  
{
   str mystr
   
   uint a = uint( "100" )
   mystr = str( a )
}

Related links