109 karma · joined Apr 5, 2021 (5y ago) · 71 submissions
comment 1mo ago · link · parent
Yes it's in another thread.
clx provides a simpler, stackless C++ API because it doesn't use the Lua VM.
The Lua C API compatibility layer lets you reuse existing binary modules without rewriting their source code. The wrapper is there for compatibility, not because modules must be written that way.
For new modules, you can use clx's native C++ API directly.
comment 1mo ago · link · parent
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.
comment 1mo ago · link · parent
My point is about deploying standalone applications.
Tools like srlua, luastatic, and many others, package Lua scripts with the interpreter and required libraries. These bundled executables can sometimes trigger antivirus false positives, just like tools such as py2exe for Python. They use packaging techniques that can resemble those used by malware, which is why I called this approach "hacky".
comment 1mo ago · link · parent
Static linking itself is not a problem for Lua.
If all you want is a tiny script that checks the weather or downloads a file, having to manually link or bundle all those pieces just to ship a standalone executable is a lot of work. That's one of the problems clx aims to solve.
comment 1mo ago · link · parent
comment 1mo ago · link · parent
comment 1mo ago · link · parent
As for AI, I've spent months of my free time building clx. The design and implementation are mine. It's true that I use AI to help with documentation and to debug complex issues, but that doesn't make the project AI-generated.
11.
Trials and Tribulations of Native Lua Compilation(samyeyo.github.io ↗)
30 points · by _samt_ · 1mo ago · 21 comments
12.
Show HN: Clx 0.4.0 – native compiler for Lua(samyeyo.github.io ↗)
3 points · by _samt_ · 2mo ago · discuss
comment 4mo ago · link · parent
I'd be very interested in your feedback once you've had a chance to explore the codebase. Multi-platform GUI support is definitely something I'd like to see emerge through Clx binary modules and the C++ API.
Feel free to reach out on GitHub when you're ready — additional platform expertise would be greatly appreciated.
comment 4mo ago · link · parent
Love.js is already a mature solution for running Love2D games in the browser through WebAssembly. Clx currently focuses on ahead-of-time compilation to native executables rather than web deployment.
The idea I was referring to is more about native distribution: compiling Lua code into standalone executables without requiring a Lua runtime on the target machine.
That said, if Clx eventually gains a WebAssembly backend, it could become an interesting alternative path for Lua-to-web deployment.
comment 4mo ago · link · parent
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.
comment 4mo ago · link · parent
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!
comment 4mo ago · link · parent
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.
comment 4mo ago · link · parent
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.
comment 4mo ago · link · parent
- clx compiles directly from Lua source code. It has its own parser and C++20 code generator; it does not use Lua bytecode
- The goal isn't necessarily to beat Lua, but some workloads benefit from the optimizations performed by modern C++ compilers.
As for tables, clx doesn't use a naive boxed-object model. Tables have a split array/hash layout: integer keys are stored in a contiguous array, while other keys use an open-addressed hash table. That keeps common accesses cache-friendly and avoids a lot of pointer chasing.
comment 4mo ago · link · parent
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.
comment 4mo ago · link · parent
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.
comment 4mo ago · link · parent
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.
comment 4mo ago · link · parent
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.
27.
Show HN: Clx – Compile Lua to Native Executables Through C++20(github.com ↗)
143 points · by _samt_ · 4mo ago · 32 comments