hi,<br>
<br>
i try to use pyrex to do a python binding for newton game dynamics
(<a href="http://www.newtondynamics.com">www.newtondynamics.com</a>) and would need some help to get started.<br>
<br>
<br>
<br>
<br>
<br>
the header looks like that:<br>
<br>
<span style="font-family: courier new,monospace;">typedef struct NewtonWorld{} NewtonWorld;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">// Newton callback functions</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">typedef void* (*NewtonAllocMemory) (int sizeInBytes);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">typedef void (*NewtonFreeMemory) (void *ptr, int sizeInBytes);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">// world control functions</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">NEWTON_API NewtonWorld* NewtonCreate (NewtonAllocMemory malloc, NewtonFreeMemory mfree);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">NEWTON_API void NewtonDestroy (const NewtonWorld* newtonWorld);</span><br>
<br>
<br>
<br>
and i have this pyrex file so far:<br>
<br>
<span style="font-family: courier new,monospace;">cdef extern from &quot;newton.h&quot;:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; ctypedef struct NewtonWorld</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; ctypedef NewtonAllocMemory</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; ctypedef NewtonFreeMemory</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; NewtonWorld* NewtonCreate(NewtonAllocMemory malloc, NewtonFreeMemory mfree)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; void NewtonDestroy(NewtonWorld* newtonWorld)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"><br>
def create():</span><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; cdef NewtonWorld* w</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; w = NewtonCreate(NULL, NULL)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; return w</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">def destroy(world):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; cdef NewtonWorld* w</span><span style="font-family: courier new,monospace;"><br>
&nbsp;&nbsp; w = world</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp; NewtonDestroy(w)</span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"></span><br>
<br>
<br>
<br>
the first problem is i have no idea how to ignore the memory management
callbacks. i don't need them so i tried to define incomplete types and
pass NULL but this doesn't work.<br>
<br>
the second problem is i don't know how to pass the NewtonWorld pointer around between python and pyrex?<br>
<br>
<br>
<br>
it would be very nice if someone could give me some tips! probably i am
too inexperienced to do something like this since i only know python
and no c but i guess with some help for the first few functions maybe i
could handle it.<br>
<br>
<br>
<br>
thanks in advance!<br>