Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the compilation target language in haxe

Tags:

haxe

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!");
like image 989
quant Avatar asked Mar 11 '18 13:03

quant


People also ask

Is HAXE a compiled language?

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.

What programming language does HAXE use?

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.

Is HAXE object-oriented?

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.

Is HAXE a Java?

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.


1 Answers

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
}
like image 131
Gama11 Avatar answered Sep 20 '22 02:09

Gama11