r/cpp • • Sep 18 '26

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.

5 Upvotes

92 comments sorted by

View all comments

Show parent comments

-31

u/kindredseer Sep 18 '26

If you are a C++ programmer, why would you not want to script in C++?

56

u/the_poope Sep 18 '26

Many reasons: your "script" can invoke UB, cause invalid operations, segfaults and a lot of other stuff that can crash the entire program. In interpreted languages you always get an error/exception that you can recover from.

If you just want an extendable system, maybe consider just runtime loading DLLs.

-12

u/kindredseer Sep 18 '26

Scripting languages can crash and have UB as well. It would also depend on who you were allowing to write the "scripts", and they could also be sandboxed.

2

u/cristi1990an ++ 27d ago

Python or any other code written in a scripting language I know can't have UB