Java: Scripting language (macro) to embed into a J

2020-06-04 05:32发布

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:

9条回答
欢心
2楼-- · 2020-06-04 05:57

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.

查看更多
趁早两清
3楼-- · 2020-06-04 06:00

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 :-)

查看更多
啃猪蹄的小仙女
4楼-- · 2020-06-04 06:00

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

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2020-06-04 06:01

You can use RelProxy - Java, it provides real and pure Java as a scripting language, including shell scripts made with Java, thanks to its compilation on the fly. Because the Java "script" is executed sharing the launcher ClassLoader, integration is straightforward.

查看更多
Deceive 欺骗
6楼-- · 2020-06-04 06:10

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).

查看更多
闹够了就滚
7楼-- · 2020-06-04 06:12

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.

查看更多
登录 后发表回答