views:

1339

answers:

14
  • What mature embeddable languages are available (or reversed, which popular languages have as a stated feature the ability to be embedded in other software)

and more importantly

  • What embeddable languages have a really good tutorial on embedding their language and extending it for your specific software

Bonus points:

  • Embeddable languages that can easily be cut down in size/features/runtime/code size/memory consumption/etc for small systems (microcontrollers, for instance)
+17  A: 

Lua has been developed for this very purpose. Scripting languages like Ruby and Python have excellent C/C++ bindings and there exist good, yet experimental (beta) bindings for .NET and Java in the form of JRuby/Jython and IronRuby/IronPython.

Konrad Rudolph
Lua is used in both World of Warcraft as well as Warhammer Online as an embedded language for add-ons. It is also pretty easy to learn.
crashmstr
+5  A: 
  • Python
  • Ruby
  • Lua

Whatever you do, please, please, please use one of these languages. Don't make the mistake of creating your own application-specific scripting language, and don't use any of the obsolete alternatives (Tcl, Guile, VBScript, etc.).

Kristopher Johnson
Would you care to elaborate on why not to use those "weird alternatives"? That might be good advice, but without knowing your reasoning how can we judge that?
Richard Turner
Basically, my reasoning is that the scripting language should be easy to pick up, and take advantage of existing programmers' knowledge and skills. Python, Ruby, and Lua are all pretty simple, and based upon current "mainstream" programming constructs. The "weird" languages I mention are not.
Kristopher Johnson
+3  A: 

I have had a really good experience with Angelscript, the documentation is pretty good and the author and community are very helpful. I have also used Lua and Python, but I found that Angelscript felt the most natural to me.

http://www.angelcode.com/angelscript/

ChalkTrauma
I also have had a really good experience with AngelScript. Of course the target audience was programmers...
Subtwo
+6  A: 
  • Tcl
  • Lua

Both of the were designed to be embedded in other programs. Personally, I prefer Tcl as I find it a lot more readable and, well, it's it's one of the most dynamic languages out available.

RHSeeger
I used to be a Tcl booster, but I think Lua is a little easier for non-porgrammer types to pick up.
Mark Bessey
+2  A: 

Angelscript is to much C like. If you're planning to share your script with programmers only it's great. But we used it once in a 3D engine, and we had a problem people, who were not exactly coders, comparing it's too comlicated.

akalenuk
+3  A: 

I would recommend Python. It's really easy to embed in any language that has decent C interoperability and there are a number of tutorials on it. It only took me a couple of hours to figure out how to embed it having no prior experience.

Also, if you're working in C++ then Boost.Python makes exposing your existing classes/functions a snap.

The one place it probably loses out to some of the others is the memory requirements.

+4  A: 

Previous tips like Lua (very preferrable) and Python / Ruby are excellent. If your software however is written in Java, there are quite some other possibilities, like:

Of course, there are also Python and Ruby implementations in Java.

BigD
a big +1 on this answer: bingo
Michael Easter
+4  A: 

My personal choice would be Python, but I recommend that you have a look at SWIG, if you are using C/C++. You can then use it to generate the wrappers for a variety of languages including Python, Ruby and Lua. It makes adding the bindings much easier.

We have used SWIG to create python bindings for our application.

David Dibben
+3  A: 

V8 JavaScript Engine is worth mentioning - supported by Google, and you are embedding a language that is easily more popular than the other suggestions. See JavaScript: The Lingua Franca of the Web.

gimel
I don't think V8 is fit for small systems. Especially since most of embedded device microcontrollers are not x86
Javier
@Javier - Some of the other (not Lua) suggestions also do not fit fit limited devices. Just thought I'd mention JavaScript...
gimel
Nobody is a bigger JS fanboi than myself, but the phrase "embedded" screams lua :)
annakata
With regards JavaScript, there's also Rhino (for the JVM), and SpiderMonkey (for C++).
stusmith
+14  A: 

Lua is not only designed specifically for this, it's very small in codesize and memory footprint, and it's the fastest non-JIT language available. And, of course, it has one of the very few full-blown JITs available for fully dynamic languages (only x86 for now).

It's written in ANSI C, and is already working in several small microcontrollers. There's a well-supported patch for non-FPU CPUs. The included libraries are all optional, so you can just not include what's not useful for your device.

here is a good summary of how Lua can help on small devices.

Javier
+3  A: 

Don't forget about PowerShell... PowerShell can be embedded in any .NET application as a scripting language.

Steven Murawski
+4  A: 

I recommend Lua.

Lua is written in ANSI C which is the lowest common denominator for languages. Lua can be integrated into an embedded C program by linking the libraries. Utilities exist to call Lua functions from C code, and C functions from Lua code. Lua has a very small footprint, making it great for embedded systems and video games.

A friend of mine integrated Lua 5.0 into a high-performance DSP application on a TI digital signal processor. There was no operating system, and a few libraries. The DSP code was written in C or assembler. He managed to port Lua to this platform. He found that using Lua on this platform approximately doubled his productivity because the edit-compile-link-load-initialize-test cycle was reduced from about 20 minutes to about 1 minute for simple changes. When he showed a demo to the customer, and the customer wasn't quite satisfied with some aspect of the code, he quickly changed the code while it was running (by transferring Lua scripts to the processor) and it then behaved properly. (The customer was impressed). The only issues they had was the occasional failure of the garbage collector, but that problem was fixed in Lua 5.1. In spite of using Lua, overall the real-time critical DSP application worked fine.

Asides from that application, Lua is known for being the valuable scripting language embedded in platforms such as World of Warcraft and many other games and game engines.

I put up a video on YouTube that shows how to use Lua with the SQLite database.

Jay Godse
+2  A: 
none
+1  A: 

I've seen Python inside quite a few software packages, and it seems to be working just fine (I'll mention just Tecplot 360 cause it's currently open in the other window, but there are a lot others).

ldigas