I'm trying to create a binding to libpython using scheme's FFI. To do this, I have to get the location of python, create the ffi-lib
, and then create functions from it. So for instance I could do this:
(module pyscheme scheme
(require foreign)
(unsafe!)
(define (link-python [lib "/usr/lib/libpython2.6.so"])
(ffi-lib lib))
This is all well and good, but I can't think of a way to export functions. For instance, I could do something like this:
(define Py_Initialize (get-ffi-obj "Py_Initialize" libpython (_fun -> _void)))
...but then I'd have to store a reference to libpython (created by link-python) globally somehow. Is there any way to export these functions once link-python is called? In other words, I'd like someone using the module to be able to do this:
(require pyscheme)
(link-python)
(Py_Initialize)
...or this:
(require pyscheme)
(link-python "/weird/location/for/libpython.so")
(Py_Initialize)
...but have this give an error:
(require pyscheme)
(Py_Initialize)
How can I do this?