12.12.1 Getting started with Haxe/Lua

To get started with Haxe for Lua, it's necessary to pick a Lua version and install dependencies. All versions of Lua are supported, but may require different libraries. Lua 5.1, 5.2, 5.3, and LuaJIT 2.0 and 2.1 (beta) are supported.

Lua is a very lightweight language that ships with a much smaller feature set than Haxe. In some cases (e.g. regex), it's necessary to install supplementary libraries that are used to support basic Haxe functionality.

In order to cover all dependencies, it is recommended to install and use LuaRocks. However, if you do not utilize relevant behavior (e.g. regex) on a given platform, or if you are using an embedded Lua client, then it is not necessary to install any packages for basic language functionality.

With LuaRocks, install the following packages:

luarocks install lrexlib-pcre2
luarocks install luasocket
luarocks install luasec
luarocks install luv
luarocks install luautf8
luarocks install hx-lua-simdjson

On Lua 5.1 or Lua 5.4+, install the bit32 library:

luarocks install bit32

When developing for multiple Lua versions, it is recommended to use the Python package hererocks.

With Lua installed, it is possible to write a simple command line application.

Create a new folder, and save this class as Main.hx.

class Main {
    static function main() {
        trace("hello world");
    }
}

To compile, run the following:

haxe --lua out.lua --main Main
More information