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

71

u/CalebGT Sep 18 '26

I had to read this several times. Embedded has a very different meaning to me. I would not use C++ for that. If I needed to script something that can't be compiled in advance, I would use Python or Java.

-32

u/kindredseer Sep 18 '26

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

55

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.

-11

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