[C++-sig] detecting if a function is written in python or C++

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Thu Jan 12 11:19:37 CET 2006


Hello,

je me rends compte que je t'ai répondu mais j'ai pas mis la réponse pour
la ML ... comme j'étais sur le webmail de mon labo j'ai plus de trace du
mail ... tu pourrais le forwarder sur la ML s'il te plait ?

Merci,

Pierre

Mathieu Lacage a écrit :
> hi,
> 
> I would like to be able to detect if the function/method I am calling
> from python is implemented as python or as c++ code in a boost python
> wrapper. Is this possible in a simple way ? The "inspect" python module
> does not seem to contain any reference to this sort of information.
> 
> A use case for this would be the following python code where the Event
> class is a c++ wrapper which calls back into the python "notify" method
> and whenre CppEvent is a c++ wrapper which calls back into a c++ method.
> 
> class __MyEvent__(Event):
>     def set_callback (self, function, *args):
>         self.__function_ = function;
>         self.__args_ = args;
>     def notify (self):
>         self.__function_ (*self.__args_);
> 
> def make_event(function, *args):
>     #if function is python code, do this:
>         ev = __MyEvent__ ();
>         ev.set_callback (function, *args);
>     # otherwise, do something smarter to make the c++ 
>     # Event::notify method call directly in the c++ function 
>     # rather than go through the __MyEvent__.notify method 
>     # and then back to the c++ function.
>         ev = CppEvent ();
>         ev.set_callback (function, *args);
>     return ev
> 
> Mathieu

-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68



More information about the Cplusplus-sig mailing list