Reputation: 3
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?
Upvotes: 0
Views: 233
Reputation: 297
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")};
}
}
Upvotes: 1
Reputation: 222
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};
}
}
Upvotes: 0