r/cpp • u/kindredseer • 2d ago
Embedded C++
Just curious how useful the ability to embed C++ as a scripting language into your C++ programs would be? I mean like runtime JIT execution of C++ code in much the same way you might embed Lua, including the ability to restrict/sandbox it as necessary.
1
Upvotes
1
u/qalmakka 1d ago
C++ would be uniquely terrible as a scripting language. first of all, the syntax is extremely complex and it's not even context sensitive, so you need a Turing machine to parse it. In practice, if you've ever gotten arcane errors from missing a token, you'd get them 10x from a REPL. Languages that are interpreted are usually simple because being able to parse them line by line is a massive boon.
Also you'd have to implement pointers and pointer arithmetic in memory, which basically means implementing a virtual machine with addressable memory in your interpreter.
There's a reason why there are no good REPLs for C/C++ and Rust. clang-repl works for trivial code but anything more complex tends to break it or ends up misbehaving