Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As you probably figured out, the problem in the call</p> <pre><code>bot.event_set(VP.EVENT_OBJECT_CLICK, click) </code></pre> <p>Indeed, the third argument <code>click</code> is a <strong>Python</strong> function object which you are passing in <code>event_set</code> to <code>vp_event_set</code>. Alas <code>vp_event_set</code> is expecting a <code>VPEventHandler</code> that is a <strong>C</strong> function pointer of type <code>void(*VPEventHandler)(VPInstance);</code></p> <p>I think I would build a dictionary associating to a <code>VPInstance</code> (<code>void *</code> pointer casted as integer) an instance of some <code>PyEvent</code> class which should contains itself the function click. Using that you can ensure that you need on one C function as callback. </p> <p>In <code>foo.pxd</code>:</p> <pre><code>cdef class PyEvent(object): cdef VPInstance instance cdef object py_callback </code></pre> <p>In <code>foo.pyx</code>: events = dict()</p> <pre><code>cdef void EventCallBack(VPInstance instance): PyEvent ev = &lt;PyEvent&gt; dict[events[&lt;size_t&gt; self.instance] ev.py_callback(ev) cdef class PyEvent(object): def __init__(self, click): self.instance = vp_create() self.py_callback = click def event_set(self, eventname): global events events[&lt;size_t&gt; self.instance] = self return vp_event_set(self.instance, eventname, EventCallBack) </code></pre> <p>I don't have a chance to test this, so I hope it more or less works. Also I would recommend asking on cython-users@googlegroups.com as they are usually really helpful and more expert than me.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload