Hi HN,

clx is an ahead-of-time compiler for standard Lua that generates C++20 and produces standalone native executables through GCC, Clang or MSVC.

The project started as an experiment to see whether modern C++ could be used as a portable compiler backend instead of LLVM or direct machine code generation. The generated code is then compiled and optimized by the host toolchain.

The latest release replaces the previous NaN-tagged value representation with a new shadow-types implementation, adds full int64 support, improves native arithmetic code generation and adds ARM64 macOS coroutine support.

Performance is typically much faster than the Lua interpreter and can outperform LuaJIT on some computation-heavy workloads while remaining fully ahead-of-time compiled.

The repository also contains graphical examples written in Lua, including a Pong game and a Mandelbrot explorer using a Sokol binary module (using the clx C++ API)

I'd be very interested in feedback on clx :)

Does the backend output c++20? If so, why? I’m curious what specific features you guys are using from c++20.

Have c++20 coroutines been useful at all?

Yes, Clx generates C++20.

The main motivation wasn't a particular C++20 feature, but using GCC, Clang and MSVC as a portable optimization and code generation backend instead of LLVM or custom machine code generation.

As for coroutines, no. Clx doesn't use C++20 coroutines because Lua coroutines are stackful, so the runtime uses platform-specific context switching instead.

My understanding of the original question is: what motivated you targeting C++20 instead of e.g. C++17

My bad ! There wasn't a strong reason to target C++20 specifically. I simply choose the latest standard available at the time as started experiments.

In practice, the code generator doesn't rely heavily on C++20-only features, so targeting C++17 would likely be possible with some adjustments.

Interesting project! I have not looked to closely at the source so forgive me for asking

- Are you doing a source to source or byte code to source transformation? - How are you beating lua performance, since the naive implementation of a dynamic language would require tons of tables with pointer chasing

Anyone know if there’s still a community around https://github.com/snabbco/snabb ? This seems like something they would appreciate.

Besides that, first use case that comes to mind is that gamedev likes Lua but iOS does not like LuaJit in JIT mode.

Yes, game development is one of the use cases I had in mind. Since Clx is fully ahead-of-time compiled, it avoids the JIT restrictions present on iOS and relies on the platform's normal native toolchain.

But Clx currently only supports Linux, Windows and macOS, including Apple Silicon. I haven't tested it on iOS yet, so I can't claim iOS support at this stage.

Neat, did you take any inspiration from Shedskin? It is a Python to C++ compiler.

The perf numbers look decent. What optimizations are you the most proud of?

Do you have plans for eval? what would stop you from supporting eval?

I wasn't familiar with Shedskin, I'll take a look !

The optimization I'm most proud of is native type specialization when possible, allowing many values to stay as int64_t or double instead of generic slow Lua values.

As for eval, Clx is fully ahead-of-time compiled. Supporting it would require embedding an interpreter in the runtime and use an interface with Clx... making it significantly larger and going against the idea of compiling everything ahead of time.

For dynamic code execution, the Lua interpreter is probably the better tool.

Interesting, will be pairing this with my Funnel setup and see how it goes.

Fennel the lisp on Lua or something else?