Dear Holger, that sounds like it could solve most of my problems! Thank you very much! I will try to implement it over the next few days.
Best regards, Karl ----- Original Message ----- From: "Holger Brandsmeier" <brandsme...@gmx.de> To: "Development of Python/C++ integration" <cplusplus-sig@python.org> Sent: Friday, December 7, 2012 2:30:16 PM Subject: Re: [C++-sig] Extending classes Dear Karl, I have one idea that may help you. Say you have a class `MyClass` with a method `func` where you want extra code to be excecuted when that function is called from python. I would add a function `MyClass_func` which is a function outside a class that has the same return code as `func` and takes the same arguments, excepts that it additionally has `MyClass& self` as its first argument. The type `MyClass&` can also be varied, e.g. `boost::shared_ptr<MyClass>`. Inside `MyClass_func` you can do whatever you want, and finally you call `self.func(...)`. In boost::python you simply export `&MyClass_func` instead of `&MyClass::func`. This worked for some of my applications, but might not be suitable in some inheritance cases. I would need more information on your application to see if this would be applicable. -Holger On Fri, Dec 7, 2012 at 2:22 PM, Charly Bicker <legord...@gmx.net> wrote: > Dear all, > > currently, I am revisiting an problem I had with my project some time ago: > due to several external constraints, I need to do some work if certain member > functions of my classes are called from python. Initially, I put the > additional code in the wrappers which were exposed with boost::python. > Unfortunately, I also have cases were objects are instantiated in C++ parts > of the code and then handed to python-space, which results in problems when > the member functions mentioned above are called. I described the problem > already earlier, cf. > http://mail.python.org/pipermail//cplusplus-sig/2012-September/016753.html. > > Unfortunately, I never found a solution to this problem. Can I somehow > execute additional code when member functions are called from python, even if > the object was instantiated in C++ (i.e. is not a wrapper class). Is there a > way to use a global function for this? I cannot touch the C++ code too much, > although a "friend" declaration might be possible. > > Thanks in advance for your help! > > Best regards, > Karl Bicker > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig