On Sun, 29 Oct 2006 09:08:27 -0700, David Harvey <[EMAIL PROTECTED]> wrote: > You CAN export module-level cdef functions from one pyrex module to > another.
I didn't realize this... > I added the following to arith.pyx: > > ========================== > cdef public int my_function(int x): > return x+1 > ========================== > > > I didn't add anything to arith.pxd. > > Then pyrexc generates a file "arith.pxi". > Then I added the following to modular/modsym/p1list.pyx: > > ========================== > include '../../ext/arith.pxi' > > def test_my_function(x): > return my_function(x) > ========================== > > > And I can call test_my_function from external python code and it works > as expected. > > The weird thing is that I can't make it so that you need to call e.g. > sage.ext.arith.my_function. It really becomes global, which is probably > not such a good thing. It's global only to the module (not to all SAGE or something). That's definitely confusing. > Probably still better hygiene to keep things in classes as they are > currently. WAIT !!! I just figured out something cool. (1) Take the line from from arith.pxi and copy it into arith.pxd. (2) Delete "include '../../ext/arith.pxi'" from p1list.pyx. (3) Now access to the module-level function works with full scoping, e.g., def test_my_function(x): return sage.ext.arith.my_function(x) -- Here's everything I did for my test: (1) In arith.pyx I put: cdef public int foo(x): return x*x (2) In arith.pxd I put: cdef extern int foo(object) (3) In p1list.pyx I put: def test_foo(x): return sage.ext.arith.foo(x) --- After building, from the interpreter I did this: sage: import sage.modular.modsym.p1list as p sage: p.test_foo(10) 100 --- --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---