Integrate Python in a C/C++ application
Dirk Gerrits
dirk at gerrits.homeip.net
Fri May 16 05:01:42 EDT 2003
Jacky Buyck wrote:
> Hi all.
> I'm studying solution to embed scripting langage in C/C++ application.
> I'll not learn you anything if I say you that giving to an application the
> power of scripting you give it a more longer life.
> FOr the moment I've mainly focused my attention around Lua and Ruby. But
> I want to know if I can do the same with Python ? In Lua it's really simpe.
> In Ruby I'ven't make any test for the moment. I know that some game use
> Python for their scripting langage so I want to know if it's simple to
> control the logic of an application using Python ?
Using Boost.Python (http://www.boost.org/libs/python/doc/index.html) it
is relatively straightforward. Check out the embedding-part of the
Boost.Python tutorial:
http://www.boost.org/libs/python/doc/tutorial/doc/embedding.html
We're currently working to make it even more straightforward in the
future by adding a convenient interpreter class, BTW.
Another option is to use the Python C/API directly.
(http://www.python.org/doc/current/ext/ext.html) This has the
disadvantage that you'll have to do the reference counting of Python
objects manually instead of letting Boost.Python take care of that.
Manual reference counting is rather error prone, especially when using
C++ exceptions and/or functions with multiple return paths, so I advise
you to take a look at Boost.Python.
Regards,
Dirk Gerrits
More information about the Python-list
mailing list