[Pyrex] defining module constants
Robert Bradshaw
robertwb at math.washington.edu
Fri Apr 11 11:29:25 CEST 2008
On Apr 10, 2008, at 11:52 AM, Rob Shortt wrote:
> Hello,
>
> I'm creating some python bindings to a C library. I've defined
> everything from the lib's header file in my pxd file and would like to
> expose many of the defined enums in my pyrex module, not as members
> of a
> class, but toplevel to my module.
>
> For example, in my pxd file I have stuff like:
>
> cdef extern from "directfb.h":
> ctypedef enum DFBResult:
> DFB_OK
> DFB_FAILURE
> DFB_INIT
> DFB_BUG
>
> and so on...
>
> What can I add to my pyx file so that my resulting module will have
> these, like:
>
> import directfb
> print directfb.DFB_OK
>
>
> Please don't tell me I have to redefine or reassign them all in my pyx
> file, but some equvalent to PyModule_AddIntConstant(m, "DFB_OK",
> DFB_OK)
> would be ok.
I don't know of an automated way to do this, but perhaps we could
make it so an enum could be declared "public" and all its members
exported to the surrounding module (though one probably doesn't want
those symbols in everything that uses your .pxd file.
One thing to note is that nothing prevents anyone from writing
directfb.DFB_OK = 389
or even
directfb.DFB_OK = "got you!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20080411/0544138f/attachment-0001.bin
More information about the Pyrex
mailing list