_samt_
When your application depends on several Lua and binary modules, you may have to compile each binary module, embed the Lua scripts while preserving their expected module paths, link everything against the Lua VM, and write glue/loading code to make everything work together (see the comment below regarding LuaSocket)
Of course, it's possible. But it's a lot of manual work, especially for newcomers.
With clx, the goal is simple: compile your Lua program into a native executable. No stock Lua VM dependency, no glue code, no module-loading code to write.
Show HN: Clx 0.4.0 – native compiler for Lua
https://samyeyo.github.io/clx/
clx is a native compiler that compiles Lua 5.5 scripts to standalone executables. Version 0.4.0 is out, focused on performance and stability :- New generational garbage collector- Faster function calls- Faster table iteration using next(), pairs(), ipairs()- Faster string operations using SIMD instructions on x64 and ARM64- Optional dynamic execution of Lua code using an embedded Lua VM with...
The release archive currently extracts directly into the working directory. I'll package future releases into a dedicated top-level directory to avoid cluttering the extraction location.
Loading precompiled CLX modules is a different problem though. In theory, a native module could be loaded and executed with a restricted environment, similar to how Lua modules receive a specific `_ENV`.
It's not something CLX supports today, but it's much closer to the project's goals than runtime compilation of Lua source code.
One challenge is that standard Lua does not provide a way to change a function's `_ENV` after compilation (unlike the old `setfenv/getfenv` mechanism from Lua 5.1).
I've been considering adding environment manipulation capabilities to the CLX C++ API (while keeping Lua compatibility intact). If that happens, loading CLX modules into custom environments could become relatively straightforward.
This is exactly the kind of scenario where I think third-party clx modules make sense: keep the core runtime portable and let platform-specific bindings live outside of it.
A clx-objc (or metal-cpp or any gui backend) module would be an interesting experiment, and the same approach could apply to other platforms (Win32, GTK, etc.)
Clx is still a relatively young project, so please be a bit indulgent with bugs or missing features, but I'd definitely be interested in seeing/helping what you build!
Since clx generates portable C++, targeting WebAssembly through Emscripten is theoretically possible.
The challenge is that Love2D does not really expose its backend as a reusable library.
A more natural fit could be a game library like SFML or raylib, used as the base of a game engine provided as a third-party clx module.
That's an interesting idea, but I'd probably lean towards a third-party clx module rather than adding Objective-C runtime support directly to clx.
Since clx already exposes a C++ API and is able to link clx modules, projects like metal-cpp are a natural fit and don't require any changes to the runtime, or any FFI tricks.
That keeps the core runtime small while still allowing platform-specific integrations.
Could that change one day? Maybe, but it's not a priority right now.
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.
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.
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.
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.
But here’s the real game-changer: rtc supports full static compilation, meaning you can embed Lua binary modules directly into your executable—and they’ll load seamlessly via require() just like regular Lua files. This opens the door to packaging powerful native extensions without worrying about external dependencies.
Static Lua binary modules need just to be recompiled with the lua54-static.lib library from LuaRT distribution (rtc is coded using LuaRT).
Here are the main features :
- Standalone tool – No Makefile or external compiler needed
- Build Windows desktop or console apps
- Static or dynamic executables
- Embed any files – Lua modules, assets, configs
- Access embedded files directly from Lua
- Easy deployment – No Lua installation required
Key Features
- Beginner-Friendly: Lua’s straightforward syntax makes Luart approachable for novices, while still enabling complex tasks—like crafting GUIs or handling web requests—with concise code.
- Lightweight Runtime: The LuaRT runtime is compact and self-contained, relying on no external libraries, ensuring minimal overhead and easy deployment.
- Object-Oriented Programming: LuaRT enhances Lua with robust OOP support, including multilevel inheritance, mixins, constructors, destructors, properties, and more, for structured and reusable code.
- Asynchronous Programming: LuaRT includes a Task object for asynchronous operations, supporting async/await/after paradigms to simplify non-blocking code (e.g., running tasks in the background or scheduling delayed actions).
- Batteries Included: LuaRT contains lots of modules to cover most of today’s programming tasks, such as: json data parsing, audio playing and recording, clipboard access, Windows registry management, process control, compression, sqlite for database operations, C FFI module to call C functions from your Lua scripts, and more ...
- Enhanced ui Module with Windows light/dark themes, HighDPI support, WebView2 widget for displaying web content, and interact with it from Lua, Hardware-accelerated Direct2D rendering with the Canvas widget.
- Bundled Development Tools: LuaRT Studio IDE, RTBuilder a RAD designer, and rtc, the Lua to executable compiler.
- Documentation: A thorough guide (over 1,000 pages) covers modules, examples, and tutorials,...
Maybe such a big solution is not needed for tiny sized projects ?
Maybe we don't need fatty big executables for the ease of deployment ?