Version blocks
Version blocks allows one to write platform-specific code. For example:
#!ooc
runThing: class {
version (windows) {
// use CreateProcess ...
return
}
version (!windows) {
// use something more unix-y
}
}
Version blocks support complex binary expressions, like &&, ||, !, and
any depth of parenthesis nesting. For example:
#!ooc
version (!(osx || linux)) {
// not on osx, nor on linux
}
Available version blocks and their corresponding C defines are as follow:
| Identifier | Description |
| windows | Windows OS, both 32 and 64-bit |
| linux | Linux |
| solaris | Solaris |
| unix | Unices (Apple products do not define this) |
| beos | BeOS |
| haiku | Haiku (BeOS-like) |
| apple | All things apple: iOS, OSX |
| ios | iOS: iPhone, iPad |
| ios_simulator | iOS compiled for the ios simulator |
| osx | Mac OSX (consider using apple instead) |
| freebsd | FreeBSD |
| openbsd | OpenBSD |
| netbsd | NetBSD |
| dragonfly | DragonFly BSD |
| cygwin | Cygwin toolchain |
| mingw | MinGW 32 or 64-bit toolchain |
| mingw64 | MinGW 64-bit toolchain |
| gnuc | GCC (GNU C) |
| msvc | Microsoft Visual C++ |
| android | Android toolchain |
| arm | ARM processor architecture |
| i386 | Intel x86 architecture (defined by GNU C) |
| x86 | Intel x86 architecture (defined by MinGW) |
| x86_64 | AMD64 architecture |
| ppc | PPC architecture |
| ppc64 | PPC 64-bit architecture |
| 64 | 64-bit processor architecture and toolchain |
| gc | Garbage Collector activated on compilation |
The specs in italics are “complex” specs - they can’t be in a composed version expression, e.g. this is invalid:
#!ooc
version (64 && osx) {
// code here
}
Consider doing this instead:
#!ooc
version (64) {
version (osx) {
// code here
}
}
The reason for this is that osx, ios, and ios_simulator are not simple #ifdefs
in the generated code, but they require an include and an equality test.
Line continuations
Any line can be broken down on several lines, by using the backslash character, \,
as a line continuation:
#!ooc
someList \
map(|el| Something new(el))
If it wasn’t for that \ before the end of the line, map would be interpreted as
a separate function call, and not a method call.
Constants
Some constants are accessible anywhere and will be replaced at compile time with strings. Those are:
__BUILD_DATETIME____BUILD_TARGET____BUILD_ROCK_VERSION____BUILD_ROCK_CODENAME____BUILD_HOSTNAME__
Call chaining
While not technically a preprocessor feature, the following code:
#!ooc
a := ArrayList<Int> new(). add(1). add(2). add(3)
Is equivalent to:
#!ooc
a := ArrayList<Int> new()
a add(1). add(2). add(3)
Itself equivalent to:
#!ooc
a := ArrayList<Int> new()
a add(1)
a add(2)
a add(3)