views:

1048

answers:

8

I am writing a graphics application in Java. Eventually I would like to build in a scripting language so things are programmable. Which language library do you recommend?

Likely suspects are:

Less likely candidates are:

The target audience are probably not hardcore programmers, so less arcane language is preferred. My guess is that JavaScript is more acceptable by them even with its quirks just because they've seen it more.

Lua seems to be popular in C/C++, but at least LuaJava requires additional .dll/.so, which makes deployment complicated.

EDIT: PhiLho wrote that there's a Java implementation of Lua called kahlua.


Related questions:

+7  A: 

if the target audience is "no programming skills...." choose jython (python) it is easy to learn. (my 7 year old daugther learned it very quick)

Bruce Eckel made a chapter with jython in "thinking in java".

at the danger getting a "down-vote" python is easier as BASIC :-)

Blauohr
+1 for -BASIC ;o)
das_weezul
+1  A: 

Lua is appreciated, among other things, by the simplicity of the language, making it easy to learn. LuaJava uses the original Lua implementation, making it complete, but as you point it, maybe delicate to install. I know at least a pure Java implementation of Lua: Kahlua. It is not complete (lacking coroutine support among other things, but one can do much without them) but perhaps already usable for your goal.
Unlike, say, Groovy, it shouldn't add much overhead to your application...

PhiLho
+1  A: 

There's also BeanShell, which has the advantage of being a fully-approved JSR, and so perhaps more likely to stick around.

http://www.beanshell.org/

skaffman
Plus side: it's basically dynamic Java, so it's really easy to attach it to a Java program. Minus side: it's basically dynamic Java, so it might not be the easiest language to learn.
Michael Myers
If I like Java, and I use Java, but I don't want my users to know that they are running Java app, is that sort of like being ashamed of ugly girl friend? No, right?
eed3si9n
A: 

You might consider Jacl. It is based on Tcl which was originally designed to be an embeddable scripting language. So, one could argue it is much more suited for that purpose than other scripting languages that had the ability to be embedded tacked-on.

Particularly if the target audience is "not hardcore programmers", Jacl makes a fine choice. Intelligent people (and especially those without hard-wired programming prejudices) can easily pick up the Tcl syntax in a morning.

Bryan Oakley
+2  A: 

If you wanted to go all out you could utilize scripting for the Java Platform as defined by JSR 223. Taking that approach would allow the application to utilize any language that has a conforming script engine.

laz
"The Mozilla Rhino engine for the JavaScript programming language, however, is currently included as a feature in the JDK 6 and JRE 6 libraries." Does this put Rhino slightly ahead of everyone else?
eed3si9n
In theory it does. I'm not really sure that is what has happened in reality yet.
laz
+1  A: 

Java 6 already has javascript available as a JSR 223 scripting language, out of the box.

johnstok
It ships with Rhino, which I commented on laz's answer too. In theory, this is the official endorsement.
eed3si9n
+1  A: 

I just read Steve Yegge's The Universal Design Pattern. The article is on much broader topic than just embedded scripting in Java application, but since the author writes a Java application that allows scripting (using Jython), there are insightful points I found interesting.

And JavaScript is one of the two best scripting languages on the planet, in the most correct sense of the term "scripting language": namely, languages that were designed specifically to be embedded in larger host systems and then used to manipulate or "script" objects in the host system. This is what JavaScript was designed to do. It's reasonably small with some optional extensions, it has a reasonably tight informal specification, and it has a carefully crafted interface for surfacing host-system objects transparently in JavaScript.

In contrast, Perl, Python and Ruby are huge sprawls, all trying (like C++ and Java) to be the best language for every task. The only other mainstream language out there that competes with JavaScript for scripting arbitrary host systems is Lua, famous for being the scripting language of choice for the game industry.

I agree with him on narrowing down to JavaScript and Lua.

Without the examples handy, all I can do is say that using JavaScript/Rhino (or Lua, once it became available on the JVM) might have made my life easier.

I personally prefer JavaScript on Java platform. The population of the user base is larger. As Yegge puts it, it is "the world's most misunderstood programming language," but the amount of resource available on the language is a plus. Rhino seems to a matured beast.

eed3si9n
A: 

I'm currently looking for a library that will allow me to use Java objects and methods from Lua scripts.

My first idea was to use LuaJava too, but as I want this to work on Linux, Mac and Windows, I was put off by the fact that it uses a compiled lib in addition to the Java stuff. Only Windows pre-compiled binaries are available, and I'm not an expert on Mac, so I tried to find something in pure Java, and I found this: http://sourceforge.net/projects/luaj

It seems to implement the C API described in the Lua doc, as well as the API from LuaJava.

The project seems really advanced, there are examples of Swing calls from Lua (!), and they worked on my Linux box. But oddly, mailing lists, forums and documentation are really sparse.

I'm gonna try this on Windows and Mac, too. Hope it works.

Kahlua has been mentioned, but it's only targeted at J2ME, that's why it lacks some parts of Lua. I think there's a project called Mochalua that has the same goals.

LuaJ, on the other hand, comes in two versions, one targeted at J2SE that implements everything (coroutines, too), and one targeted at J2ME, which lacks 2 or 3 libs I think (including the LuaJava stuff, which needs reflection).

Ced-le-pingouin