C2PY_MODULE_INIT
The C2PY_MODULE_INIT annotation lets us define a function that will be called when the module is initialized/imported.
C++ code
// c2py_module_init.cpp
#include "c2py/c2py.hpp"
#include <iostream>
// This function should be called when the module is initialized (imported) in Python.
C2PY_MODULE_INIT void init() { std::cout << "c2py/clair rocks!" << std::endl; }
Usage in Python
After generating the extension module, we can use it in Python:
>>> import c2py_module_init
c2py/clair rocks!
Importing the module triggers the execution of the init function, which prints a message to the console.