My goal is to get the directory in which the executable is located. For other sys targets I was using Path.directory(Sys.programPath())
but looks like Sys.programPath()
doesn’t work in interp and fails with a not very informative error:
Main.hx:
function main()
trace(Sys.programPath());
$ haxe --run Main
Results in
[0] Instance prototype not found: haxe.macro.Error
Is it expected behavior? I understand that in interp scenario it’s not entirely clear what the “program path” should be but is there a good solution for my task?
My current idea is to run the program in a bash script and passing the scripts path through an environment variable. Like this:
run.sh:
#!/bin/bash
export EXEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
haxe --run Main
and then use Sys.getEnv('EXEDIR')
instead of Path.directory(Sys.programPath())
.
It works but this solution feels a bit weird…
I’m using Haxe 4.2.5 on Mac (Apple M1)