Brief Notes on Haxe

John Gabriele

2018-10

Some brief notes on Haxe. (A work in progress.)

Links

Languages comparable to Haxe include Dart, Kotlin, Swift, and Reason.

Getting Started

Install

If you don’t have any preference, use Haxe 4 with the HashLink target. See this Getting-Started doc.

Note that there is HashLink the haxe output target (haxe -hl), as well as HashLink the VM. There are two ways to use HashLink (aka “HL”):

In both cases, you get the same HL runtime. See the HL site for more info.

Editor Setup

Geany works out of the box. (The Emacs Haxe mode is pretty old.) See also this list of editors and IDEs.

hxml files

Since some haxe build commands may contain numerous arguments which you’d rather not have to type repeatedly, you can create .hxml files that contain those args. As a simple example, for a typical hello world program, create an interp.hxml file containing:

-main Main
--interp

Then you can run

haxe interp.hxml

rather than having to type out haxe -main Main --interp.

Haxelib

The Haxe online package repo and library management tool is haxelib (see the haxelib docs). See haxelib --help.

Packages/projects you install via haxelib are often named lowercase with hyphens if necessary. The package files themselves are .zip files, and its haxelib.json file is the package config file.

By default, haxelib installs and unpacks packages into ~/haxelib. This is your haxelib-installed packages repo. Haxelib can also do project-specific repos.

Language Basics

Using Your Own Modules

In your Main.hx file, near the top:

import foo.bar.Baz;

Then have a foo/bar/Baz.hx file containing:

package foo.bar;

class Baz {/*...*/}

Control Structures

var s1 = "hard string" // no string interpolation
var s2 = 'soft string' // supports string interp

var a = ["a", "b", "c"];
var m = ["a" => 1, "b" => 2, "c" => 3];

for (x in foo) {
    trace(x);
}

for (k => v in some_map) {
    trace('$k --> $v');
}

// more to come...