1

Before simply answering "use SWIG" or "just write it to a file on disk" read this:

I have a C++ client/server program. The client requests data from the server.

The server generates data and calls various routines to check the data. If all the data is correct, it sends the data via socket to the client.

What I'd like to do is take this raw data (say it was a String type data) and replace my "various routines" with python programs.

To do this, the raw data will be passed to the python programs to be parsed and checked, then they will need to return a pass/fail value to the C++ server.

Any ideas?

dulac
  • 201
  • 1
  • 2
  • 7

1 Answers1

1

That's quite backwards from the normal way of doing things, isn't it!

You have two main options:

  1. Keep the Python scripts as they are, run them using fork()/exec() or whatever is appropriate to your platform, and parse their output in C++;
  2. Use CPython's well-documented API to embed it in your C++ program, and invoke the scripts that way.
Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
  • Looks like #2 is going to be best for me. Thanks! – dulac Jan 20 '12 at 15:45
  • 1
    I don't know about that "well-documented". If find myself going to the actual Python sources to find out what is required, or what a "documented" function actually does. And of course, the simplest option would probably to do everything in Python. – James Kanze Jan 20 '12 at 16:11
  • Similarly, I could do everything in C++. I like the idea of having a core C++ and allowing Python "plug-ins" – dulac Jan 20 '12 at 16:44