4

I am making some kind of sandbox-engine, the end-users are able to make scripts to make their world dynamic etc, currently I am only looking at LuaJava because I have quitte some experience with Lua and find it a very readable/easy language. But I also understand that it might be a bad idea to choose only based on personal preference, after all Lua is meant to be embedded into C so performance wont be the best I imagine.

But after a look at some of alternatives (Groovy, Clojure) I find the syntax just unreadable/too abstract, Lua was my first programming experience and even that was quite hard to 'get' at first, I'm afraid these languages would just have scared the crap out of me and I would never have looked at scripting again.

Are there scripting languages that can be embedded in Java that compete with Lua on simplicity?

Edit My problem with JavaScript, JPython is all the braces etc, as a starting user symbols tend to look 'hard'. Also for python there is the concept of Object's that the user needs to comprehend and isn't that useful in this case.

func = function(arg)
   print(arg)
end

Is so simple...

2
  • If Lua is meant to be embedded into C, then you'll likely find that it has much superior performance, not the other way around. Commented Jun 26, 2011 at 12:52
  • @DeadMG well according to a benchmark I just found you are right, guess that makes Lua simply the best option I have. Commented Jun 26, 2011 at 12:55

2 Answers 2

6

I think JavaScript is very simple, and it can be embedded in Java quite easily via Rhino. Scripts can be both pre-compiled, or compiled on-the-fly via the javax.script classes, which are used to connect to script engines for the Java platform (of which Rhino is one).

If you like Lua, though, there's a Lua for Java project called — *cough* — Kahlua. They list "Fast runtime of the most common operations" as one of their goals.


Edit: Re your edit, I'm not immediately seeing why this:

func = function(arg)
   print(arg)
end

is substantially easier to understand than this:

func = function(arg) {
   print(arg);
};

...which is the literal translation from Lua to JavaScript, pre-supposing a function called print exists on your platform. I would normally write that like this instead:

function func(arg) {
   print(arg);
}

...but the other way is fine for most purposes.

But you should use what you're comfortable with.

Sign up to request clarification or add additional context in comments.

6 Comments

I know and for me you and most people on this site it's not harder. But for people who see code for the first time in their lives things such as symbols make it 'look' hard
Well I am already using a project called LuaJ (luaforge.net/docman/view.php/457/5688/README.html) which has the option to compile Lua code to JavaBytecode. They also state that they are nearly equal to most C versions in terms of speed.
@Dasdasd: Cool. (Kahlua uses the LuaJ compiler, btw.) Yes, there are a lot of languages for the JVM now; in fact, here's a list. Not all of them will come with compile-on-the-fly like Rhino does, which I'm taking as an important part of your project. :-) Best,
Thanks for the reactions, I must honestly say that your last line helped me the most. I guess I decided all along :)
@Dasdasd Avoiding languages because of brackets won't make it any easy for you in the future. Better get used to it sooner than later, because brackets aren't going away any time soon.
|
1

You should try Jython and JRuby

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.