How would I dynamically add methods to my module through the C-API? I have many functions I need to register, and they are not in the same array. I assume I can initialize the module with a NULL method table, as the documentation says that’s possible.
PyObject *mymod = Py_InitModule("my", NULL);
What is the name of a function to add my methods one at a time.
Basically, you’ll have to get ahold of the module dict first:
Store the module name in a PyString object:
Then properly populate a PyMethodDef struct
mland create a new callable:and add this callable keyed by the function name to the module dict:
I’ve obviously skipped all relevant error checks.
All this is my interpretation about what
Py_InitModule4does (Py_InitModuleis a macro callingPy_InitModule4with default arguments).