[Pyrex] pyrexembed: How to make a method which returns a struct

Lenard Lindstrom len-l at telus.net
Tue May 23 07:05:55 CEST 2006


This is not tested:

cdef class PyRoomConnection:
    cdef RoomConnection *p
    cdef set_value(self, RoomConnection *p):
        self.p = p
    property b:
        def __get__(self):
            return self.p[0].b
    ...

cdef class PyRoomConnections:
    cdef RommConnections rcs
    cdef set_value(self, RoomConnection rc):
        self.rc = rc
    def __len__(self):
        return self.n
    def __getitem__(self, n):
        cdef PyRoomConnection *p
        if n < 0 or n >= len(self):
            raise IndexError("Room connection index out of range")
        p = PyRoomCopnnection()
        p.set_value(self.rcs.rc[n]
        return p

cdef class ServerHandle:
    ...
    def getRoomConnections( self, rID ):
        cdef PyRoomConnections rcs
        rcs = PyRoomConnections()
        rcs.set_value(
            ServerHandle_getRoomConnections( self.thisptr, rID ))
        return rcs

Lenard Lindstrom
<len-l at telus.net>


On 23 May 2006 at 4:25, Martin Dobiasch wrote:

> >RoomConnections is a C structure. A python method returns a python object. It
> cannot >return a C structure. To do that you will need a wrapper extension type
> for >RoomConnections.
> 
> Thanks for all your help.
> How to write such a wrapper extension?




More information about the Pyrex mailing list