Search code examples
haxe

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

  • 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};
        }
    }