I'm really new to C++ and I've come across a problem I've not been able to solve by reading documentations.
I want to embed a script language into my c++ application. That language could be javascript, lua or preferably python.
I'm not looking for something like Boost.Python / swig, something that is able to wrap my c++ functions / classes to a python interface, but rather a python_evaluate_and_return_result_as_variable("my_code");
function.
I have a whole bunch of structs containing a few integers:
struct my_integers {
int a;
int b;
int c;
int d;
int e;
};
Now I want to do some math with these integers, for example:
i.a = i.c * i.e;
The math I want to do will be changing a lot in the future and I need people other then me be able to change the math without having access to the c++ code.
I'm thinking about a code structure like this:
i = my_python_function_cppwrapper(i)
Is something like that possible? I googled a lot for this but the only thing I seem to find are wrappers that provide c++ -> python (or the other way around) functionallity without really interacting with variables.
I'd be really thankful for any help,
Robin.
Why not use Boost.Python? You can expose your data classes to Python and execute a script/function as described here.
The Python documentation has a page on embedding Python in a C or C++ application.
If you want to simply run Python scripts from C/C++, then use the Python C API. In your C/C++ code:
PyRun_SimpleString("import math; x = math.sqrt(2 * 2)");
For more complicated things, you will have to look at the API docs, but it's pretty straightforward.
How about embedding a JavaScript engine, such as V8?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With