tags:

views:

77

answers:

3

What I'm looking for is a scripting engine for Java that would allow users to write simple scripts to control the behavior and events for a game. Something that:

  • is simple - something easy to pick up, especially for people with some basic programming/scripting experience

  • provides lots of control - I can easily start/stop/pause scripts and control how much execution time each gets, perhaps how much memory space they can use

  • is separated from the Java environment itself - No access from scripts to any Java objects or classes, only to those functions I explicitly provide

I've considered the Rhino JavaScript engine, and it would suit my purposes, but from what I've read (example), it's designed to integrate with Java so much that sandboxing it securely would be tricky. I'd rather start with an engine that gives scripts no access to anything by default, than have a fully open one that I have to close up. The scripts might not always be trusted, so the environment should not be easy to break out of.

I'd also consider developing my own language with something like ANTLR, but it's probably more effort than I want to put in.

Any suggestions?

+2  A: 

Have you considered Lua?

Google docs preview of a pdf on the subject

Lyrio, G.H.S.O; Seixas, R.B.; Using Lua as Script Language in Games Coded in Java, Proceedings of The North American Simulation and AI in Games Conference - GAMEON-NA, EUROSIS, Montreal, Canada, 2008.

kenny.r
It's Lua, not LUA. See http://www.lua.org/about.html#name
lhf
Thanks for pointing that out to me, edited.
kenny.r
+2  A: 

You should give a try to Groovy, a scripting language that easily integrates with the Java platform.

Its syntax is 100% compatible with Java, but it also has a simplified syntax that makes it a suitable language for DSLs implementation.

I don't know for sure if you can stop/pause the execution of Groovy code from a Java program, you should read the Groovy API.

When executing Groovy code from within a Java program, you can specify the context passed to the script and you can query the context modified by the script for output variables. The script can be completely isolated from the underlying Java environment by creating a GroovyShell with an appropriate CompilerConfiguration.

frm
+1  A: 

JACL is one such language. It is based TCL. Whatever you do, don't invent another language. There are plenty of good choices out there.

Bryan Oakley