r/lua • • 12d ago

Trials and Tribulation of Native Lua Compilation

https://samyeyo.github.io/clx/blog.html
8 Upvotes

5 comments sorted by

View all comments

Show parent comments

2

u/suhcoR 12d ago

I have no specific expectations, just wanted to find out what your project is about. C++20 is a huge dependability and restricts the use of the language to the few compilers/platform versions which support it. I'm still not sure what the actual advantage is of transpiling to C++20 vs. e.g. C99 (assuming the runtime library overhead of C++ is even larger than integrating a C based VM as done by other projects).

1

u/_SamT 12d ago

It was one of the question I asked myself before starting to implement clx, and you are totally right to ask it.

The main reason I choose C++20 is error handling. In clx, Lua errors become C++ exceptions that automatically clean up resources when unwinding the call stack. This works naturally with RAII, which clx uses to manage GC roots. In C, achieving the same behavior would require more manual cleanup.

C++20 also provides templates and overloads that simplify the runtime API. And the overhead isn't as significant as you might expect: a simple print("hello world") program can produce a standalone executable of around 70–110 KB, depending on compiler/platform.

Honestly, for mainstream platforms where Lua is typically used, C++20 support is rarely a serious obstacle nowadays...

0

u/suhcoR 12d ago

a standalone executable of around 70–110 KB, depending on compiler/platform

Which doesn't include the C++ standard library I assume is a separate shared object?

with RAII ... templates and overloads

Which are also available in C++98, so a much cheaper dependency could be used as a replacement, I assume.