[Pyrex] Callback with bound method
ha shao
hashao2 at myrealbox.com
Sat Jul 17 06:51:44 CEST 2004
Is this question has no answer or it just got missed?
What's is the recommend way to wrap callbacks? Anyone?
On Thu, Jul 08, 2004 at 03:52:51AM +0800, ha shao wrote:
> It seems that the recommend way of wrapping callbacks is using bound
> methods. By my attempt to do it failed:
>
>
> ctypedef void (*cbfunc)(void *userdata)
> cdef extern void add_cb(cbfunc cb, void *data)
>
> cdef class CBClass:
> cdef object _callback
> def __init__(self, callback):
> self._callback = callback
> cdef void action(self, void *userdata):
> self._callback(<object>userdata)
>
> def addhook(acb, adata):
> cdef CBClass cbobj
> cbobj = CBClass(acb)
> add_cb(cbobj.action, <void*> adata)
>
> The above code will cause pyrexc to spit out:
> test.pyx:14:16: C method can only be called
> test.pyx:14:16: Cannot assign type 'void ((struct
> __pyx_obj_4test_CBClass *,void (*)))' to 'void ((*)(void (*)))'
>
> Did I misunderstood something? The version is 0.9.2.1
>
More information about the Pyrex
mailing list