What I want to do is the opposite of what most people want to do: I have a library written in Python, and I want to make it available to C (and possibly other languages).

I know that the typical answer to this is using the Python library for C, that is:

#include <Python.h>

int
main(int argc, char *argv[])
{
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  Py_Finalize();
  return 0;
}

(source: http://docs.python.org/extending/embedding.html#very-high-level-embedding)

However, this seems less than optimal to me:

  • It is ugly
  • It's just for C

What I want, instead, is a way to bind my library to LOT of languages, including C. I don't care about automatic wrapper generation: my library is quite simple, so I can write glue code.

At the moment, the only solution I came up with is using code similar to the one above to bind my library to C. Then use SWIG to bind the C library to other languages.

Is there a better one?

Edit
Report