I’d like to detect the target language in Haxe so that I can change a function’s behavior depending on which language Haxe has been compiled to.
Example in Haxe-like pseudocode:
class Test() {
static function printStuff(toPrint) {
if (the target language is Java) {
System.out.println(toPrint);
} else if (the target language is C++) {
cout << toPrint;
} else if (the target language is JavaScript) {
alert(toPrint);
}
}
}
Is it currently possible to achieve this in Haxe?
You can use conditional compilation along with Haxe Magic to achieve this. For example: