Search code examples
haxe

How to take parameters from the command line inside the main function in Haxe?


I'm new to Haxe. My school tasked me to write a Jack compiler in Haxe, so I started learning the language. I can't find anywhere how to take parameters inside the main function. That is, I'd like to call my executable like this :

./Main.exe arg1 arg2 arg3

...and read these args inside the main function.


Solution

  • See: https://api.haxe.org/Sys.html#args.
    This method returns your passed arguments as Array<String>.

    static function main() {
        var args = Sys.args();
        var arg1 = args[0];
        var args = args[1];
        //...
    }