[Pyrex] Callbacks

Gustavo Sverzut Barbieri barbieri at gmail.com
Thu May 24 23:43:32 UTC 2007


On 5/24/07, Georg Grabler <ggrabler at gmail.com> wrote:
> Hey lists,
>
> One again me, and guess what - pyrex as a topic ;)
>
> I've some nice callback to implement, since it's used in the functions. It's
> defined with
> typedef void(*transtype) (test_struct, void*, void*)
>
> Is this possible? It's not needed though, the lib CAN handle this without
> callbacks... but it would be nice to know though.

you have to create your callback in your bindings and then use it to
call your python function, something like:

cdef void my_cb(test_struct *bin, void *data):
   params = <object>data
   func, args, kargs = params
   func(*args, **kargs)

def py_set_callback(bin_wrapper, func, *args, **kargs):
   params = (func, args, kargs)
   bin_wrapper.callback_data.append(params)  # you need something like
this to keep a reference to objects
   c_set_callback(bin_wrapper._instance, <void *>params)




-- 
Gustavo Sverzut Barbieri
--------------------------------------
Jabber: barbieri at gmail.com
   MSN: barbieri at gmail.com
  ICQ#: 17249123
 Skype: gsbarbieri
Mobile: +55 (81) 9927 0010



More information about the Pyrex mailing list