Search code examples
c++pythonembeddingextending

Create a Python3 module at runtime while initialize an embedded Python


We have a DLL that implements a custom programming language. What I want to do is adding support for the python language keeping the same code for "API function".

I have succefully embedded python in this DLL, now I'm approaching the problem to expose all the old function as a python module.

Now this DLL doesn't expose the API function as interface function but it's installed (as function pointer) to the language engine. In this way it's impossible to create a new python module (a new DLL). But I need to keep the compatibility with the old method...

It's possible to create (and install) at runtime a module defined in the same DLL where the Python is located?

I think something like calling the PyInit_xxxx method after PyInitialize();


Solution

  • I've solved using a code like this before Py_Initialize();

    /* Add a built-in module, before Py_Initialize */
    PyImport_AppendInittab("xxx", PyInit_xxx);