views:

336

answers:

7

I am looking for a good scripting language to link to my program. I am looking for 2 important attributes:

  • Scripting language should be hard linked into the executable (not requiring 3rd party installations). This is important to me to simplify distribution.
  • Scripting should allow some run-time debugging option (When running a script inside my program I would like to easily run it inside a debugger while it is running in the context of my program)

Can python,lua or some other language supply me with this?

+2  A: 

I'd put my two cents in for python. I don't know a lot of the details, but the computer graphics suite blender does a wonderful job of implementing python scripting.

As far as I can tell in blender 2.5 the interpreter is run from inside the executable,

import sys
sys.executable

shows /blender/blender.exe and there is good debugging support, it even has a full interactive interpreter inside.

For more info check out: http://www.blender.org/

nick
+10  A: 

Lua is designed for this:

Will
+13  A: 

Both Lua and Python can provide the features you mention, so choosing one of them will depend on other criteria.

Lua is a lighter weight solution, it will have a much smaller disk footprint and likely a smaller memory overhead than Python too. For some uses it may be faster. Python has a much richer standard library, more mature third party libraries and a more expressive language.

Both have been embedded into major applications. Python can be found in Blender, OpenOffice and Civilization 4. Lua can be found in World of Warcraft and Adobe Lightroom. I'd recommend looking at a few tutorials for each and the facilities available to embed them in your application and just choose the one that fits your brain best.

Simon Hibbs
Unfortunately Python is lacking real support for a "one single executable" linking. The DLL/so libs can't easily statically compiled and linked. LUA prevents the problem by not having a serious library at all.
Lothar
Civilization 5 switched to Lua for performance reasons.
Jonas
+5  A: 

Typically, Lua is the better choice for embedding into another project. Python is better as a standalone platform because the library support is so much broader. See Lua Versus Python for more details.

Personally, I use both very frequently depending on the job at hand. I always use Lua for embedding into C/C++ applications or scripting functionality that is imported from C/C++ shared libraries (i.e. a DLL). Python is always my first choice for standalone tasks that do not require low-level C/C++ code.

Judge Maygarden
+1  A: 

I really like Lua for embedding, but just as another alternative, JavaScript is easily embeddable in C, C++ (SpiderMonkey and V8) and Java (Rhino) programs.

fuzzy lollipop
+1 True, it's another viable option. I'd only recommend it if you, or more properly your user/scripters are likely to already know it. One thing I forgot to mention in my answer above is that unless you're embedding the scripting engine for your own use, you should consider the likely preferences and needs of those who will be using the scripting interface.
Simon Hibbs
Simon: I'm not sure how much I agree with that. There was a time when everyone said they wanted REXX as an extension language, and I can't name a single program I've seen with REXX in 10+ years. I don't know *anyone* who asked for Lisp for their editor (even Lisp programmers!), but look at Emacs now. Javascript (roughly 'Scheme with Java-like syntax') was originally way over the heads of the typical people writing webpages, yet somehow people managed to adjust. I think if the language is sufficiently powerful, and users want to hack your program/platform, then users will figure it out.
Ken
A: 

I'll add Tcl to the mix. It's designed to be easily embedded into other programs.

RHSeeger
+1  A: 

In addition to Tcl, Lua, and Javascript (all already mentioned), Guile is another language designed explicitly for this.

Ken