I recently discovered the existence of boost-python and was surprised at the obvious simplicity. I wanted to try and started wrapping an existing C ++ library.
While wrapping calls to the APIs of the base library is quite simple (nothing special, just regular function calls and very general parameters), I donβt know how to properly wrap initialization / cleanup functions:
Accordingly, my C ++ library requires the caller to first call mylib::initialize() when the program starts and call mylib::cleanup() before it finishes (in fact there is also an initializer object that takes care of this, but it probably doesn't matter).
How to do this using boost python?
Forcing a Python user to call mymodule.initialize() and mymodule.cleanup() doesn't seem very pythonic. Is there any way to do this automatically? Ideally, the initialize() call will be executed transparently when the module is imported, and the cleanup() call will also be executed when the python script ends.
Is there any way to do this? If not, what is the most elegant solution?
Thanks.
c ++ python boost-python
ereOn
source share