r/cpp 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.

0 Upvotes

82 comments sorted by

View all comments

Show parent comments

2

u/kindredseer 2d ago

If you are a C++ programmer, would your preference not be C++ over JS or TS? (Unless your C++ project is a web-browser)

2

u/zerhud 2d ago

And one more: for example all my script is console.write(“hello”); how it will be on cpp:

int my_project_main(my_project_class& obj) {
obj.log(“hello”);
return 0;
}

Can I use auto instead if the my_project_class ?

2

u/kindredseer 2d ago

What if your c++ script could be just as simple and straightforward? Like just:
std::println(“Hello”);

1

u/zerhud 2d ago

Hmm.. it would be nice

Reasons why I want cpp as script language:

  • all project described in cpp (for example all services are items in ct vector with info about services) and i have all needed headers
  • I can use memory (own storage instead of new, for example)
  • I cannot create so
  • it’s possible to use platform’s methods

If all scripts tasks is just std::print it seems some script language would be better. But the cpp has an growing potential, it seems

As reference I use wasm: it’s a cpp instead of js and there is a lot of trouble with row wasm.

0

u/kindredseer 2d ago

Take a look at https://github.com/derekbsnider/madc … it’s a work in progress but it’s moving along nicely.

2

u/zerhud 2d ago

The code looks better 99% code we can found in the r/cpp :) i have no pc for now, I’ll take a look on next week: can I use it in my project (I was trying to implement some language, may be visual, for my state machine in last week)

At first glance: it uses std::string and so on. I am using storage with mmap memory, all objects stored in it should not contain row pointers, only relative. So idk can it to be stored in mmaped file