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?
The very popular ones are C#, C++ and Lua. Lua is a high-level programming language used for scripting in games and other tasks. It is an interpreted language just like Python; however, it is first compiled into byte code, which is then run on the Lua virtual machine.
Both C# and C++ can be used to create games. However, C++ has better control hardware on the PC or server. Therefore, it is usually a more suitable language for game development.
The Best Scripting Languages To KnowPHP: PHP is an open-source scripting language that is frequently used in back-end web development. Python: Python is known for its concise syntax. It requires less typing than many other languages. Ruby: Ruby is one of the easiest scripting languages to learn.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With