Command Line Tutorial (Neko, C++, PHP)

In this tutorial you will produce a multiplatform program using the 'Sys' class to make a command-line program that will add together two floats and print the result.

Create the project
Create a new project/folder and name it "CommandTool". Make it target neko, but you can change it to C++ or PHP later. If the main class was automatically generated, open it. If not, just create a "CommandTool.hx".

CommandTool
Paste the following into your main class: class CommandTool { public static function main { stdin = Sys.stdin; while(true) { Sys.println("Please enter the first number:"); Sys.print(">>> "); var first = Std.parseFloat(stdin.readLine); // read a line of input into the first float Sys.println("Please enter the second number:"); Sys.print(">>> "); var second = Std.parseFloat(stdin.readLine); // read a line of input into the second float var result = first + second; // set result to the sum of the floats Sys.println("Result: "+result); // print the result to the command line }   } }

Compile & Run
Make a build.hxml if it was not generated for you and compile then run the program. Enter what you want and be amazed.