views:

127

answers:

2

I'm making a falling sand game in Java. I want users to be able to write their own engine for the game and I thought a scripting language might work for that. I've tried out a small script with jython and it's many times slower than that java version.

I need a scripting language that has fast loops and/or fast array access since that's what the game will be doing a lot of. Or if you have any suggestions on another way to let users write their own engine for the game.

I'm also not entirely sure this can work (well). If you don't think it can please let me know why and maybe some possible alternatives.

A: 

JavaCC

You could write you're own simple game language with JavaCC. This does give's you all the flexibily you possibly want and native Java speed (well that actualy depends on you're implementation). But you need to keep you're syntax simple or else it will take some efford...

Java

Java? Yes Java! Why not let users extend you're game by Java code? In Java 6 there is a Java compiler API:

Beanshell vs Rhino

Some performace comparison between BeanShell and the Rhino (Javascript) interpreters (Rhino is the winner):

Kdeveloper
If you write your own language, it will inevitably wind up being slower than the mainstream scripting languages, because you don't have a decade and a dedicated community of clever people to create a decent implementation. But worse, it will propably suck (design is hard, languages are complex -> language design is very hard) and be a pain to use (due to lack of tools, documentation, bugs, etc). Stick to the established ones.
delnan
Slower? Not necessarily, that just depends on your implementation. If you compile you're syntax to Java, I don't see why it should be slower. And remember I'm not talking about a 'real' programming language either; this is just a simple rule engine for a game. Domain specific languages do have their function: http://en.wikipedia.org/wiki/Domain-specific_language
Kdeveloper
A: 

You might look at BeanShell for this. In my use it's been pretty much as fast as native Java (as that is what it becomes) and is pretty accessible as it is Java, albeit locked around Java 1.4.

Billy Hamlin