'Is there a way to get the compiler version in haxe?
I am trying to make my own terminal using the haxe programming language. I am wondering if there is any way to get the haxe compiler version. I know that you can type haxe -version in the command prompt to get it but I need it in the code. Is there a way to do this?
Solution 1:[1]
There is a library you can use to get compiler version
https://lib.haxe.org/p/version/
or just use a macro from it
class Main {
static public function main() {
trace(StaticExtender.getHaxeCompilerVersion());
}
}
class StaticExtender {
public static macro function getHaxeCompilerVersion():haxe.macro.Expr {
var proc_haxe_version = new sys.io.Process('haxe', [ '-version' ] );
if (proc_haxe_version.exitCode() != 0) {
throw("`haxe -version` failed: " + proc_haxe_version.stderr.readAll().toString());
}
#if (haxe_ver >= 4)
var haxe_ver = proc_haxe_version.stdout.readLine();
#else
var haxe_ver = proc_haxe_version.stderr.readLine();
#end
return macro $v{haxe_ver};
}
}
Solution 2:[2]
It is also available as a compiler define which can be read using macros. haxe_ver seems to be available since 3.2 at least, you might want to check if you need to work with older compiler versions.
class Test {
static function main() {
trace(getCompilerVersion());
}
static macro function getCompilerVersion() {
return macro $v{haxe.macro.Context.definedValue("haxe_ver")};
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ilir Liburn |
| Solution 2 | tokiop |
