In PLT scheme, can I export functions after another function has been called?

Posted by Jason Baker on Stack Overflow See other posts from Stack Overflow or by Jason Baker
Published on 2010-05-27T18:43:16Z Indexed on 2010/05/28 18:52 UTC
Read the original article Hit count: 185

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?

© Stack Overflow or respective owner

Related posts about c

    Related posts about Scheme