开发者

Simple interpreter to embed and extend inside an C++ Windows application [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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开发者_如何学Go for this request, what are your experiences and suggestions?


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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜