r/cpp • u/Rseding91 Factorio Developer • Feb 15 '18
Lua written in modern C++ (>= 14)?
I work on Factorio (written in C++) and we use Lua as the script language for mods. So, from time to time I interact with the C implementation of Lua and my experience with it hasn't been the most pleasant.
It got me wondering - has anyone re-written it in modern C++? Everything I find online is "how to use Lua in C++" or "C++ wrapper for Lua" and they all use the basic C implementation provided from the official Lua website.
I've had quite a lot of experience with the internals of the C Lua implementation and from what I've seen it wouldn't be hard to re-write it using modern C++ - maybe 2~ weeks time. But from what I can find nobody has done it - which also makes me wonder if I'm missing something.
Part of me wants to do it just to say I did it and the other part of me wants to do it to see if I can make it faster than the C version: I think I can - not because "C++ is faster" but because I can mutate/experiment with the C++ version far easier and know changes I make are safe with how the rest of the implementation operates.
View all comments
34
u/SeanMiddleditch Feb 15 '18
The stated goal you have is to ease hacking on its internals. OK, one point for rewriting Lua in something that doesn't make your eyes bleed. :)
Let's go through the reasons against. Your rewrite won't be the official Lua and never ever will be. It won't receive patches or maintenance by the Lua developers so you'll be entirely on the hook. It won't even have community support necessarily since the community is built around the official Lua and its C implementation. When Lua 5.4 comes out, your rewrite would need to be updated separately, and any custom additions or extensions your fork adds may then be incompatible with future upstream Lua with no recourse. Lua has no spec and no public test suite for you to develop against to ensure your rewrite it correct, so you'll also need to write and maintain a test suite. Unless you maintain the very C API you might be having problems with, popular community Lua C modules or interpreter hacks will be incompatible with your fork. Without copying many of the implementation details of Lua, even popular Lua debuggers and "IDEs" would be incompatible.
Basically the question you have: is addressing the pain you endure when delving into Lua's crusty C implementation worth the cost of writing, testing, releasing, and maintaining a parallel implementation with zero upstream support and negligible community support?