Note that there are some explanatory texts on larger screens.

plurals
  1. POPass a callback function from python to c using cython
    primarykey
    data
    text
    <p>First off I want to say that I do not have the option to modify or even view the c source code so anything that involves modifying the c file will not be helpful.</p> <p>In VP.h:</p> <pre><code>typedef enum VPEvent { ... EVENT_OBJECT_CLICK, ... } ... typedef void *VPInstance; typedef void(*VPEventHandler)(VPInstance); ... VPSDK_API VPInstance vp_create(void); ... VPSDK_API int vp_event_set(VPInstance instance, VPEvent eventname, VPEventHandler event); ... </code></pre> <p>In VP.pyx:</p> <pre><code>cdef extern from "VP.h": ... cdef enum VPEvent: ... VP_EVENT_OBJECT_CLICK, ... ... ctypedef void *VPInstance ctypedef void(*VPEventHandler)(VPInstance) ... VPInstance vp_create() ... int vp_event_set(VPInstance instance, VPEvent eventname, VPEventHandler event) ... ... EVENT_OBJECT_CLICK = VP_EVENT_OBJECT_CLICK ... cdef class create: cdef VPInstance instance def __init__(self): self.instance = vp_create() ... def event_set(self, eventname, event): return vp_event_set(self.instance, eventname, event) </code></pre> <p>What I want to have In Python:</p> <pre><code>import VP ... def click(bot): bot.say("Someone clicked something!") ... bot = VP.create() bot.event_set(VP.EVENT_OBJECT_CLICK, click) </code></pre> <p>This is how you would do it in c:</p> <pre><code>#include &lt;VP.h&gt; void click(VPInstance instance) { vp_say(instance, "Someone clicked something!"); } int main(int argc, char ** argv) { ... VPInstance instance; instance = vp_create(); ... vp_event_set(instance, VP_EVENT_OBJECT_CLICK, click) } </code></pre> <p>However the problem is that when compiling VP.pyx I get</p> <blockquote> <p>Cannot convert Python object to 'VPEventHandler'</p> </blockquote> <p>As well, by default the callback is given a VPInstance pointer but I want to abstract this value into a class.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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