Hi All,<br><br>Thanks for considering this. I think Lenard Lindstrom got it pretty right.<br>Greg, consider callabcks which take functions as parameters.<br><br>gobj_callback_resize(gobj *g, void (*func) (gobj *g);<br><br>
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.<br>I use a global dict with instance_id as key and the callback func as value.
<br><br>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.<br><br>Sure if the callback is implemented it will make the code much cleaner.
<br>psuedo code will look something like this<br><br>cdef extern from "g.h"<br> gobj_callback_resize(gobj *g, void (*func) (gobj *g))<br>
<br>cdef class ABC:<br> cdef gobj *g<br><br> def __init__(self):<br> self.g=init_gobj()<br> self.resize_callback=None<br> <br> cdef callback cb_func (gobj *g):<br> 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
<br><br> def register_resize_callback(python_callback_func):<br> self.resize_callback=python_callback_func <br> gobj_callback_resize(self.g,self.cb_func)<br><br>Thanks<br>
<br><div><span class="gmail_quote">On 10/10/06, <b class="gmail_sendername">Greg Ewing</b> <<a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Lenard Lindstrom wrote:<br><br>> No, I think "Test Drive" understands this. What is requested is some<br>> way to make a C functions a class attributes. That way a C callback<br>> function can be directly associated with the class that uses it.
<br><br>I think the OP needs to explain more clearly<br>what the problem is before we can help further.<br>I'm rather confused at this point.<br><br>--<br>Greg Ewing, Computer Science Dept, +--------------------------------------+
<br>University of Canterbury, | Carpe post meridiem! |<br>Christchurch, New Zealand | (I'm not a morning person.) |<br><a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz
</a> +--------------------------------------+<br><br>_______________________________________________<br>Pyrex mailing list<br><a href="mailto:Pyrex@lists.copyleft.no">Pyrex@lists.copyleft.no</a><br><a href="http://lists.copyleft.no/mailman/listinfo/pyrex">
http://lists.copyleft.no/mailman/listinfo/pyrex</a><br></blockquote></div><br>