Here are my settings: I have next c++ class which I want to wrap:
// Foo.h
class Foo
{
public:
typedef int MyType;
typedef int ArgType1;
typedef int ArgType2;
...
typedef MyType (*FooFunction) (ArgType1 a, ArgType2 b);
...
void setFooFunction(FooFunction f);
Example of using this class in c++:
#include "Foo.h"
...
int fooFun(int a, int b)
{
if (a > b) return a;
else return b;
}
...
int main(int argc, char **argv)
{
...
fooObj->setFooFunction(&fooFun);
...
}
Cython wrapper:
# .pyx
cdef extern from "Foo.h":
cdef cppclass Foo:
void setFooFunction(int *) except +
def bar(fooFun):
...
fooobj.setFooFunction(fooFun)
...
And I want to be able to do this:
# python file
...
def pyfun(x, y):
return x + y
...
def main():
bar(pyfun)
I'm not familiar with Cython completely, but I've already tried to do some magic and it doesn't work:
# .pyx
cdef extern from "Foo.h":
cdef cppclass Foo:
void setFooFunction(int *) except +
ctypedef int (*myFun) (int, int)
def bar(fooFun):
cdef myFun funpointer
funpointer = (<myFun*><size_t>id(smoothfun))[0]
...
fooobj.setFooFunction(<int*>fooFun)
...
Is it even possible to do such things?