views:

133

answers:

4

I need a simple interpreter which will do execution (evaluation) of simple expressions/statements and also call functions from main C++ applications. At the moment I do not need scripting of the application, but it may be useful later.

It should also be strait-forward for other team members to pull my application from Source Repository and to build it, without having to install additional application, libraries, etc. Searching reveled options like: Python (via Boost and / or Python API), Lua, Guile, TinyScheme.

I am the closest to Python, but using Boost, building Python library, complicated task of interfacing main application with Python makes this choice an overkill, maybe I am wrong.

There should be a simple solution for this request, what are your experiences and suggestions?

+1  A: 

Guile is easy to embed and extend, and scheme if powerfull programming language.
You can compile libguile and add it to the repository in lib directory or add source for guile and compile it when user compile the project.
But I don't try to use guile on Windows.

jcubic
I am not sure how much of a foothold has guile taken in windows applications, generally there are no major applications scripted in guile, its revival may change that.
boskom
+3  A: 

Two great options you've already listed are Python and Lua. Here are some of the tradeoffs for your consideration:

Python

  • A much more complete and powerful language (IMHO!) with libraries for anything and tons of support and communities everywhere you look.
  • Syntax is not entirely C-like
  • Although Python wasn't designed specifically for embedding (it's much more often used as a standalone language extended by code in C/C++), it's tot really hard to embed. The official docs contain some examples, and following Boost's examples shouldn't be much harder.

Lua

  • Designed from bottom up for embedding, so it should be the simplest one to embed.
  • Syntax more C-like than Python's

If you foresee a definite future need for scripting, building in a scripting engine early is a good idea as it may open some interesting possibilities for you as you go on developing the program. Both options listed above are good ones, you should have no problems embedding any of them without much effort.

Eli Bendersky
+3  A: 

If you only want to evaluate arithmetic expressions, try ae, a simple interface to Lua for that task.

lhf
As far as I can see from README.txt it is an C extension which works on top of Lua (so lua lib is required for building it I guess). Can it evaluate statements like: if Conditon1 and Codnition2 or condition3 than return X?
boskom
Yes, but since ae assumes it is evaluating expressions, you have to use Lua idiom as a replacement for a conditional operator. It might be easier to just use Lua directly in that case. You can build Lua from source directly in your project if you don't plan on loading extension modules, or use it in a shared library if you do. Both are very easy to accomplish even on Windows.
RBerteig
+2  A: 

No matter which scripting language you choose (and I would probably vote for Python), you might consider using SWIG (www.swig.org) to ease the burden of interfacing to C++. While normally used to build C++ extensions for python (or ruby, lua, guile, any many others), it can be used to aid in embedding too.

You had mentioned boost::python, which is certainly a full featured option, and allows for a somewhat closer Python/C++ integration (especially where virtual functions are involved). However, in my experience, SWIG is a lot easier to integrate, works with scads of scripting languages, and for python, is natively supported by Python's distutils.

Matthew Hall