O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—Interacting with the user

Now, we're going to create an application that takes your name as a parameter, greets you, and displays the number of characters in your name.

  1. Copy the following code in a file named Main.hx
    class Main
    {
    public function new()
    {
    }
    public static function main()
    {
    var name = neko.Sys.args()[0];
    trace("Hello " + name);
    trace("Your name is " + Std.string(name.length) + " characters long.");
    }
    }
    
  2. Open a terminal; go to the directory where you saved Main.hx and type the haxe main Main -neko characterCounter.n command.
  3. Type the command (this is an example with my first name):

    neko characterCounter.n Benjamin

  4. You will see the following output:
    Main.hx:12: Hello Benjamin
    Main.hx:13: Your name is 8 characters long.

What ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required