ctypes:passing python class instances through c and back

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Jul 30 01:25:19 EDT 2007


En Thu, 26 Jul 2007 12:18:04 -0300, m2i3k <m2i3k2000 at gmail.com> escribió:

> I have C code with requires me to register a python callback. I am
> able to get the callback working well using ctypes if I use global
> functions without any context argument for the callback.
>
> Now I want to register a python class member function for callback,
> and give "self" as the context argument at the time of callback
> registration. Then the c code can invoke the callback with self as the
> context argument

Use a bound method as the callback -that is, get the method from an  
instance, not from the class-.
Pass it the same way as you would pass a global function; you get the  
"self" argument for free :)

-- 
Gabriel Genellina




More information about the Python-list mailing list