On Sat, Feb 7, 2009 at 3:21 PM, Lisandro Dalcin <[email protected]> wrote:
> BTW,  a feature I really miss from the times I was a heavy SWIG user
> is the ability to include verbatim C code snipets...
>

Warning: blatant hack below; just for fun.

You can put verbatim C code snippets in Cython by abusing cdef extern.
 Here is an example that illustrates doing this to wrap some C++ code.
 I wanted to put the verbatim C++ code "a[b]=c" in, so I did it like
so.  You
could put any C/C++ code inside that macros though, not just a[b]=c.

cdef extern from "vector.h":
    ctypedef struct intvec "std::vector<unsigned int>":
        int get_entry "operator[]"(int n)
    intvec intvec_factory "std::vector<unsigned int>"(int len)

cdef extern from "":
    void DEFINE_SET "#define SET(a,b,c) a[b]=c; //"()
    void SET(intvec, int, int)

DEFINE_SET()

cdef intvec v = intvec_factory(10)
SET(v,2,399283)
print v.get_entry(2)

Obviously you should never do this :-)

 -- William
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to