TheNickmaster21
TheNickmaster21

Reputation: 275

Using the Java Scripting API w/ JavaScript and/or Lua

So, I just realized that Java has a built in API system that works with JavaScript and apparently other scripting languages that are JSR-223 compliant. Now, I'm designing a game engine and I'm wondering if I should just use the integrated JavaScript support or figure out how to use Lua.

QUESTION: Can the Java Scripting API easily support Lua? If so, how?

If you feel like it: Would it be unknown to do the scripting side of a game engine in JavaScript?

EDIT: I need scripting capabilities for my engine to allow the creation of AIs, special voxels (Like blocks in minecraft) and other add-ons to the game. I'm not set on doing all this creation in a scripting language because the difficulty of doing so but a scripting language appears as a good alternative to making JARs for all game content. I'm simply exploring what I can do with Java.

Upvotes: 0

Views: 643

Answers (2)

Alex
Alex

Reputation: 1017

The Java Scripting framework relies on the code implementing JSR-223 being written in Java. As such lua won't work.

However, you can use an implementation of lua written in Java such as luaj which has JSR-223 support included.

Note: luaj is not a complete clone of lua but it's pretty functional and allows you access to java classes etc.

On the subject of choosing a scripting language, as you are using Java as your system programming language, some of the benefits of using lua as a scripting language don't apply e.g. fast, small footprint, excellent C integration.

So really it becomes a personal preference. Javascript would be probably be fine, as would Jypthon, JRuby or luaj.

Upvotes: 1

Silviu Burcea
Silviu Burcea

Reputation: 5348

It is not a wise idea to make a game engine in JS. Despite possible(see Node.js / Three.js), JS is rather slow because is interpreted. Node.js has JIT compilation, but it's still 3-4x(best case) slower than C++ equivalent.

I never used Lua or Java Scripting API, I cannot give you an answer on this, but I think the speed of JS will change your mind.

Upvotes: 0

Related Questions