I'm writing a C++ program that requires Python (3.11) code to be embedded into it and am using Python.h to try and accomplish this. The general idea is that my a python script, which will be stored by the C++ program as a string, as I'll be performing operations on the source at runtime, will contain a "main()" function which returns an array of known size.
I'm aware I can do it via:
...
PyObject *pName = PyString_FromString("main");
PyObject *pModule = PyImport_Import(pName)
...
However, in order to actually execute the script, I would need to write it to a file just so that python could read it again. This adds extra time to execution that I'd prefer to avoid. Isn't there some way in which I can pass python the source code directly as a string and work from there? Or am I just screwed?
EDIT: BTW, PyRun_SimpleString does not do what I want, as it doesn't return anything from the executed code.