Embedding python (or other scripting languages) into a C++ program


I'd like to implement functionality in C++ but give users the ability to write scripts in a language like Python.  These scripts would exists as separate files, which they could edit as regular python (or whatever) scripts.  They would call my C++ functions but the control structures would be native to the scripting language.      

Sorry if this is muddled.  I can clarify.

LVL 1
Mike1066Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fl0ydCommented:
What exactly is your question? It is possible and easy to extend an application with scripting using Python, although I'm not exactly a fan of its syntax. There is a load of links on this page http://www.vendian.org/language_year/ in the Python section that may be useful to you. Also, boost has a Python interface -- to see it at work have a look at http://www.flipcode.com/cgi-bin/msg.cgi?showThread=COTD-PythonCPP&forum=cotd&id=-1 . Hope this was the direction you were looking for. If not, feel free to clearify what exactly you are after.

.f
chofreitherCommented:
There is extensive documentation on embedding Python at http://www.python.org/doc/current/ext/ext.html. Also, fl0yd's recommendation for the Boost library is a good one if you want to export C++ classes to Python (or the other way around). See http://www.boost.org/libs/python/doc/index.html.

However, if you don't need the exhaustive class library that Python offers, I think you could be happier with Lua (http://www.lua.org). It's much smaller in footprint and, I think, also faster than Python. It offers only the minimum in built-in functions and lets the host application provide the relevant functionality, which is often what you want from a scripting language. Many free and commercial applications (including, for instance, Lucas Arts' Escape from Monkey Island) have already employed it for scripting with good success.

Clemens

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.