[Pyrex] classes and callbacks

Test Drive testdrive6 at gmail.com
Wed Oct 11 10:15:39 UTC 2006


Hi All,

Thanks for considering this. I think Lenard Lindstrom got it pretty right.
Greg, consider callabcks which take functions as parameters.

gobj_callback_resize(gobj *g, void (*func) (gobj *g);

Here if there are 10 instances of the class , each registering a diff
function for the cb, I need to keep track of which instance registered which
function.
I use a global dict with instance_id as key and the callback func as value.

The workaround by Lenard Lindstrom is pretty good.  Look at the cb example,
I need to have gobj *g in both the classes and way (sandwich function) to
copy the pointer from one class to other.

Sure if the callback is implemented it will make the code much cleaner.
psuedo code will look something like this

cdef extern from "g.h"
         gobj_callback_resize(gobj *g, void (*func) (gobj *g))

cdef class ABC:
      cdef gobj *g

      def  __init__(self):
            self.g=init_gobj()
            self.resize_callback=None

      cdef callback cb_func (gobj *g):

do_anything_here_u_have_access_to_ptr_g_based_on_which_u_can_call_other_c_funcs_of_the_lib_or_manipulate_this_instance's_attributes

      def register_resize_callback(python_callback_func):
               self.resize_callback=python_callback_func
                gobj_callback_resize(self.g,self.cb_func)

Thanks

On 10/10/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>
> Lenard Lindstrom wrote:
>
> > No, I think "Test Drive" understands this. What is requested is some
> > way to make a C functions a class attributes. That way a C callback
> > function can be directly associated with the class that uses it.
>
> I think the OP needs to explain more clearly
> what the problem is before we can help further.
> I'm rather confused at this point.
>
> --
> Greg Ewing, Computer Science Dept,
> +--------------------------------------+
> University of Canterbury,          | Carpe post meridiem!
> |
> Christchurch, New Zealand          | (I'm not a morning
> person.)          |
> greg.ewing at canterbury.ac.nz
>         +--------------------------------------+
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.copyleft.no/pipermail/pyrex/attachments/20061011/c3480694/attachment.html 


More information about the Pyrex mailing list