fizban
fizban

Reputation: 597

What is a good, simple scripting language to embed into a Java game engine?

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:

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?

Upvotes: 7

Views: 2693

Answers (4)

frm
frm

Reputation: 3496

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.

Upvotes: 2

Jacek Cz
Jacek Cz

Reputation: 1906

In my opinion not only language, but way of interfacing is important. JSR 223 is most compatible between different languages, but "native" seems the best (i.e. full object integration of groovy)

Upvotes: 0

Bryan Oakley
Bryan Oakley

Reputation: 386382

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

Upvotes: 1

Kenny Rasschaert
Kenny Rasschaert

Reputation: 529

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.

Upvotes: 4

Related Questions