Let's create an application that will simply display the "Hello World" message. We will use only cross-platform code and will compile it to neko to begin.
Main.hx
class Main { public static function main() { trace("Hello World"); } }
Downloading the example code for this book
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.
Main.hx
and type the haxe main Main neko helloworld.n
command. neko helloworld.n
.Main.hx:5:Hello World
As you've guessed, the program just wrote "Main.hx:5:Hello World" in our terminal and ended.
Main
, which has a public and static function main
. The method trace
is a method that allows one to debug an application by printing a message along with the file's name and line number of the call. If you don't really understand what classes are, don't worry, we are going to explain it to you soon. -main
switch that's followed by the name of the class containing the function has to be executed when launching the program. This function has to be a static function named main
that takes no parameters. helloworld.n
file.3.144.227.9