Detect target language in Haxe

c++, haxe, java, javascript

Solution

You can use conditional compilation along with Haxe Magic to achieve this. For example:

#if java
    untyped __java__("java.lang.System.out.println(toPrint);");
#elseif js
    untyped __js__("alert(toPrint);");
#elseif ...
    ...
#end

Problem

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?

Original source