Haxe - Print command line arguments
Asked Answered
I

1

5

Using the Haxe programming language, is it possible to print the command line arguments that are passed to an application?

I'm trying to re-write this Java program (which simply prints the command line arguments) in Haxe.

public class JavaExample{
    public static void main(String[] args){
        for(int i = 0; i < args.length; i++){
            System.out.println(args[i]);
        }
    }
}
Inerrable answered 30/10, 2012 at 4:46 Comment(1)
It looks like there might be a solution for php, neko, and cpp (using the Sys class, specifically Sys.args): haxe.org/api/sysInerrable
B
10

Since targets like JS(in browser) and Flash do not have concept of command line arguments. Haxe put such "system" target things in Sys and the top level sys package.

class Example {
    public static function main():Void {
        for (arg in Sys.args())
            Sys.println(arg);
    }
}
Begrime answered 30/10, 2012 at 6:3 Comment(9)
Is it possible to compile Haxe to Javascript (when Javascript is being used outside the browser, e.g., in a node.js server?)Inerrable
Also, is the Sys class available for every target language (or just one or two of them)?Inerrable
Sys is "available in neko, php, cpp" according to its doc (right below its class name).Begrime
Is the documentation likely to be up-to-date at this time, or is it possible that it contains outdated information (which may not reflect the current state of the Haxe programming language?)Inerrable
The online doc is always in sync with the latest release version(at the moment it is Haxe 2.10).Begrime
I remember seeing this package: lib.haxe.org/p/nodejs which a few of these comments seem to be requesting. It adds the Sys object and sys package to JavaScript for Node.JS, but I haven't tried it just yet. You can install it with haxelib.Pauperism
It's only me or Sys.args()[0] is NOT the own process name?!?Tiltyard
@VíctorR.Escobar No, Sys.args()[0] is not the own process name. Sys.executablePath() may or may not give what you want depended on the target you use.Begrime
Thanks for the clarification.... Sys.argv[0] in some script languages is equal to Path.withoutDirectory(Sys.executablePath()) in haxeTiltyard

© 2022 - 2024 — McMap. All rights reserved.