[SciPy-user] callbacks in weave

Eric Jones eric at enthought.com
Tue May 6 01:12:10 EDT 2003


Close.  You have to build an argument tuple, and the use the function object's call() method.  The following should do the trick:

from weave import inline

def foo(x,y):
     print "In Python's foo:"
     print 'x',x
     print 'y',y

def cfoo(x,y):
     code = """
     printf("Attemtping to call back foo() from C...\\n");
     py::tuple foo_args(2);
     foo_args[0] = x;
     foo_args[1] = y;
     foo.call(foo_args);
     printf("Done.\\n");
     """
     inline(code,"foo x y".split() )

eric

Fernando Perez <fperez at colorado.edu> wrote ..
> Hi all,
> 
> I wonder if it's possible to call-back into python from weave-inlined code
> snippets. The included tutorial makes a passing mention of callable objects,
> but with no details.  I tried the code below but failed to make much progress.
>   Any help would be greatly appreciated. (For reference, I'm using a fairly
> recent CVS snapshot, from  a week or two ago).
> 
> Thanks in advance,
> 
> Cheers,
> 
> f.
> 
> 
> # Code snippet below:
> 
> from weave import inline
> 
> def foo(x,y):
>      print "In Python's foo:"
>      print 'x',x
>      print 'y',y
> 
> def cfoo(x,y):
>      code = """
>      printf("Attemtping to call back foo() from C...\\n");
>      foo(x,y);
>      printf("Done.\\n");
>      """
>      inline(code,"foo x y".split() )
> 
> x=99
> y="Hello"
> 
> print "Pure python..."
> foo(x,y)
> print "Via weave..."
> cfoo(x,y)
> 
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user


More information about the SciPy-User mailing list