Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding a scripting engine in C++

I'm researching how to best extend a C++ application with scripting capability, and I am looking at either Python or JavaScript. User-defined scripts will need the ability to access the application's data model.

Have any of you had experiences with embedding these scripting engines? What are some potential pitfalls?

like image 982
Tony the Pony Avatar asked Dec 02 '22 05:12

Tony the Pony


2 Answers

Lua is also a great candidate for embedding in programs. Its very self contained, and even the native cross-language call system isn't bad.

For JavaScript, your best bet right now is to look at V8 (from Google), which is easy enough to work with.

like image 156
Yann Ramin Avatar answered Dec 03 '22 19:12

Yann Ramin


It's sure easy to embed Python by using the Boost::Python library (ok, ok, sarcasm.) Nothing is "easy" when it comes to cross-language functionality. Boost has done a great deal to aid such development. One of the developers I've worked with swears on the Boost->Python interface. His code can be programmed by a user in Python, with a REPL built right into the UI. Amazing.

However, my experience has been better observed using SWIG and other languages such as Java. I'm currently working with SWIG to wrap C++ with Python. There's all sorts of gotchas with exceptions, threading, cross-language polymorphism and the like.

I'd look at these two places first. As I said, nothing will be "easy" but both these make life more livable.

like image 24
wheaties Avatar answered Dec 03 '22 19:12

wheaties