haxe

Topics related to haxe:

Getting started with haxe

Haxe is an open source toolkit that is capable of compiling to many different target languages and platforms.

It consists of:

  • the Haxe programming language - a modern, high-level, and strictly typed programming language
  • the Haxe standard library - a collection of general purpose, system, and target-specific APIs
  • the Haxe compiler - a fast, optimising cross-compiler with metadata support, dead code elimination (DCE), completion mode, resource embedding, runtime type information (RTTI), static analyzer, macros, and more

Haxe has been used to create games, web, mobile, desktop, and command-line applications, as well as cross-platform APIs.

As of Haxe 3.3.0-rc.1, Haxe can compile to sources / bytecode of the following languages: ActionScript 3, C#, C++, Flash, HL, Lua, Java, JavaScript, Neko, PHP, and Python.

Haxe has a package manager, Haxelib, which is bundled with Haxe. It also has a custom build file format, .hxml, which offers an easier way of passing arguments passed to the Haxe compiler.

References

Abstracts

An abstract type is a compile-time type which resolves to the underlying type at run-time. This means that thee abstract type does not exist in the source code generated by the Haxe compiler. In its stead are placed the underlying type, or types defined for implicit casting.

Abstracts are denoted by the abstract keyword, followed by an identifier, and underlying type in parentheses.

Abstracts may only define method fields and non-physical property fields. Non-inlined method fields are declared as static functions in a private implementation class, accepting as an additional first argument the underlying type of the abstract.

Note that operator overloading is only possible for abstract types.

Loops

Enums

Branching

All branching expressions make it possible to return evaluated expressions. This means branching results can be assigned to variables. In this case, all expressions that can be evaluated by a successful condition test must pass type unification. If no else expression is given, the type is inferred to be Void.

Pattern matching

Pattern matching is the process of branching depending on provided patterns. All pattern matching is done within a switch expression, and individual case expressions represent the patterns.

The fundamental rules of pattern matching are:

  • patterns will always be matched from top to bottom;
  • the topmost pattern that matches the input value has its expression executed;
  • a _ pattern matches anything, so case _: is equal to default:.

When all possible cases are handled, the catch-all _ pattern or default case is not required.