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.&nbsp; 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 &quot;g.h&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gobj_callback_resize(gobj *g, void (*func) (gobj *g))<br>
<br>cdef class ABC:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cdef gobj *g<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def&nbsp; __init__(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.g=init_gobj()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.resize_callback=None<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cdef callback cb_func (gobj *g):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp; &nbsp; &nbsp; def register_resize_callback(python_callback_func):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; self.resize_callback=python_callback_func &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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> &lt;<a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz</a>&gt; 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>&gt; No, I think &quot;Test Drive&quot; understands this. What is requested is some<br>&gt; way to make a C functions a class attributes. That way a C callback<br>&gt; 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,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Carpe post meridiem!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>Christchurch, New Zealand&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| (I'm not a morning person.)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<br><a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz
</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+--------------------------------------+<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>