Advanced formatting
Every method must reside in an object, and objects can reside in packages. Methods are defined using this syntax (tags in curly braces are optional).
{owner tag} {operator} ({arguments})
// examples
void do_something()
- integer get_integer()
+ string light_name()
boolean exists(integer i)
decimal find(integer i, string s)
Packages can be in other packages, in a tree hierarchy.
package graphics
package 3D
package OpenGL
class OpenGLrenderer
class renderer
package DirectX
class DirectXrenderer
The full name of the class OpenGLrenderer is graphics.3D.OpenGL.OpenGLrenderer. Classes can see other classes defined in the packages above it, this means that the class OpenGLrenderer can automatically see classes defined in OpenGL, 3D, graphics and the base package.
To reduce tabbing, decending into two or more packages at the same time is possible. The example above involving different types of renderers can also be written as this.
package graphics.3D
class renderer
package OpenGL
class OpenGLrenderer
package DirectX
class DirectXrenderer
Also classes can be defined as being inside a package without actually defining the package.
package graphics.3D
class renderer
class OpenGL.OpenGlrenderer
class DirectX.DirectXrenderer
Even this is possible.
class graphics.3D.renderer class graphics.3D.OpenGL.OpenGlrenderer class graphics.3D.DirectX.DirectXrenderer
But this is probably not a good way to represent the package information, the example before is possibly the nicest and most compact way.
Properties and constants are defined in a similar way.
class graphics.3D.renderer
// method
void do_something()
// property
integer my_value
// constant
boolean action_on = true
// type with constant is optional (the compiler guesses) (probably not)
// string
name = "Voodoo Renderer"
// decimal
value = 1.0
// boolean
option = false
Other options in the definition of a class use this syntax.
class{: {: {: }}} // examples class renderer // subclass renderer class OpenGLrenderer : renderer // use the 2Drenderer interface class OpenGLrenderer :: 2Drenderer // can see the 2D package class OpenGLrenderer ::: graphics.2D // all the above options with another interface and package class OpenGLrenderer : renderer : 2Drenderer 3Drenderer : graphics.2D graphics.misc
Similar to classes are interfaces, they define a group of methods that a class that implements that interface must also implement. They can only contain methods. Here is it’s syntax (the same as a class but without the parent option.
interface{: {: }} // examples interface 2Drenderer // also use other interfaces interface 2Drenderer : canvas // can see other packages interface 2Drenderer :: graphics.misc // all together interface 2Drenderer : canvas : graphics.misc
Packages, classes, interfaces, methods, properties and constants can all be declared quite flexibly.