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.

6 Upvotes

92 comments sorted by

View all comments

1

u/ushumgigal Sep 20 '26

If you're going to restrict/sandbox it anyway, why would you opt for C++? Within C++?

I'm assuming the main point is to have something simpler that C++, to be interpreted in runtime.

1

u/kindredseer Sep 20 '26

That is the case some of the time... like Lua is specifically designed to be light and simple, so yes, it suits this purpose, except that its syntax isn't the best... but if that is what you need (light and simple) then Lua is perfect for that.

What I'm talking about is real C/C++ in JIT form, with the option to sandbox when required.

1

u/ushumgigal Sep 20 '26

You particularly want the C++ syntax in the scripting language, then? Which would contradict the "simple" part for most people, if not for you. I personally dislike Lua myself. To each their own.

Real C/C++ is pretty unsafe in the wrong hands, though. I doubt restricting it to at least some degree would be optional, but again, to each their own. In fact, Terry Davis did exactly what you're talking about in TempleOS, but with Holy C and not regular C/C++.

1

u/kindredseer Sep 20 '26

Well, there are many different reasons people use an embedded scripting language in their application... and only a few cases truly require sandboxing -- those in which you do not fully trust the author of the script.

Truthfully though, if your script language exposes the ability to execute shell operations -- i.e. os.execute() in Lua, subprocess.run() in Python, etc, then the scripting language already has considerable ability to do something "unsafe".

If instead, the scripting is there for the convenience of a trusted developer, then sandboxing is less of a concern.

1

u/ushumgigal Sep 20 '26

When I said `unsafe`, I was thinking about what you wouldn't want to have them done with pointers basically, but

the scripting is there for the convenience of a trusted developer

This part sums it up.

Whether a statically typed curl-bracket language is convenient for that developer, I think is subjective. :)

0

u/kindredseer Sep 20 '26

Well, if the application is being developed in C++, then why would a C/C++ script language be inconvenient for a C++ programmer?

0

u/ushumgigal Sep 20 '26

Why indeed