Skip to content

Instantly share code, notes, and snippets.

@MatthijsKamstra
Last active October 2, 2023 11:24
Show Gist options
  • Save MatthijsKamstra/59ec57cdb69844f0102a74321cef3082 to your computer and use it in GitHub Desktop.
Save MatthijsKamstra/59ec57cdb69844f0102a74321cef3082 to your computer and use it in GitHub Desktop.
Create a hello world in Haxe
-cp src
-D analyzer-optimize
-main Main
--interp
# this build file assums that you have a folder structure like this:
#
# + src
# - Main.hx
# build.hxml
#
# Run build.hxml with:
# `haxe build.hxml`
// πŸ‘‹ Hello World in Haxe
/*
Declaring an empty package. A package isn't necessary, but it's useful if you want to create
a namespace for your code (e.g. org.yourapp.ClassName).
Omitting package declaration is the same as declaring an empty package.
*/
package; // empty package, no namespace.
// Here's the class definition.
// It's the main class for the file, since it has the same name (Main).
class Main {
// a constructor
function new() {
/*
Trace is the default method of printing haxe expressions to the screen.
Different targets will have different methods of accomplishing this.
E.g., java, c++, c#, etc. will print to std out.
Javascript will print to console.log. All traces come with a default newline.
Finally, It's possible to prevent traces from showing by using the
"--no-traces" argument on the compiler.
*/
trace("Hello, World! πŸŒπŸ‘‹"); // Print a greeting
}
/*
If you want certain code to run automatically, you need to put it in
a static main function, and specify the class in the compiler arguments.
*/
static public function main() {
var main = new Main();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment