I know, I can do something like
public static function getTarget():String {
#if flash
return "Flash";
#elseif java
return "Java";
//... some more elseif clauses ...
#end
}
in order to detect the target language in haxe (see http://old.haxe.org/doc/snip/gettarget). However whenever a new target programming language gets added (ok, this is not that frequent) by the community - I would need to add another elseif-clause in order to "support/detect" that language ...
So I was wondering, if there is some kind of predefined macro/function, that returns the target language as string:
trace("This is a " + getTargetLanguage() + " program!");
Haxe consists of a high-level, open source programming language and a compiler. It allows compilation of programs, written using an ECMAScript-oriented syntax, to multiple target languages. Employing proper abstraction, it is possible to maintain a single code-base which compiles to multiple targets.
Haxe is an open source high-level strictly-typed programming language with a fast optimizing cross-compiler. Haxe can build cross-platform applications targeting JavaScript, C++, C#, Java, JVM, Python, Lua, PHP, Flash, and allows access to each platform's native capabilities.
Classes, interfaces and inheritance: Haxe allows structuring code in classes, making it an object-oriented language. Common related features known from languages such as Java are supported, including inheritance and interfaces.
For those of you who are not familiar with Haxe — probably most of you, honestly — it is a statically-typed, explicit-typing-optional, object-oriented meta-language that can produce source and binaries for Java, Python, C++, C#, Neko, Javascript, and a few others.
I don't think such a thing exists.
To make sure getTarget()
doesn't silently break when a new target is added (and you're compiling for it), you could have it throw a compiler error in that case:
public static function getTarget():String {
#if flash
return "Flash";
#elseif java
return "Java";
//... some more elseif clauses ...
#else
#error "Missing target name"
#end
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With