XorNut
XorNut

Reputation: 19

Haxe: get path to the `std` library

I need to get path to the std folder of Haxe. On Linux system it can be /usr/share/haxe/std, on Windows -- C:\HaxeToolkit\haxe\std\.

There are haxelib config, haxelib path and haxelib libpath commands, but they point me to /usr/local/lib/haxe/ folder.

How can I get this path in my script?

I tried these commands haxelib config, haxelib path, haxelib libpath but they help me only on Windows, because on Windows std and lib foldrs are in the same folder.

Upvotes: 2

Views: 172

Answers (1)

YellowAfterlife
YellowAfterlife

Reputation: 3202

There's a way to do this with Haxe:

ResolveStd.hx:

class ResolveStd {
    static macro function getStdPath() {
        var evalDir = haxe.macro.Context.resolvePath("eval");
        var stdDir = haxe.io.Path.directory(evalDir);
        return macro $v{stdDir};
    }
    public static function main() {
        Sys.println(getStdPath());
    }
}

and then

haxe --run ResolveStd.hx

will have output like

C:\HaxeToolkit\haxe\std

(explanation: we're asking the compiler to resolve path of eval, which is one of the subdirectories in std, then going one level up)

Upvotes: 1

Related Questions