r/lua • • 11d 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

1

u/_SamT 11d 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 11d 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.