Show HN: Clx – Compile Lua to Native Executables Through C++20 (github.com)

143 points by _samt_ ↗ HN
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 :)

10 comments

[ 4.1 ms ] story [ 30.7 ms ] thread
Interesting, will be pairing this with my Funnel setup and see how it goes.
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?

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?

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.

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

So the cases where you loadfile a file just for it to have a separate sandboxed _ENV that the function that created it, is flat out unsupported, forever?
As a Lua fanboy, I have to say this is really, really great!

I have not dug into it deeply enough yet - saving a deep dive for the weekend - but meantime .. what are your thoughts about having objc_msgSend included in the runtime so that native MacOS (and eventually iOS) GUI's can be made using this technique:

https://medium.com/@michael.mogenson/write-a-macos-app-with-...

This is cool, it could be a neat way to get Love2d games on the web with wasm