Java/Javascript interaction

Hello monkeys, i know this topic is not related to jme but to java in general.



I would like to allow the gamer/user to write small javascript programs which interacts with the game objects. I have googled a bit and found that executing javascript in trough the ScriptEngine would work just fine.

Unfortunately all examples i found covers only function loading and executing them and reading their return value.

My idea would require to call a set of java function from within javascript, for example:

[java]

//javascript

Tank.getWeapon("MainWeapon").setPowerOff();

[/java]

The variable Tank, as well as the functions getWeapon() and the corresponding setters and getters are java objects/functions. (Probably part of an AbstractControl)



Is this possible, and if yes can you please give me a small example, or a link to a corresponding doc?



Thank you in advance

Hi,



u can use the ScriptEngine from Java6:

http://docs.oracle.com/javase/6/docs/api/javax/script/package-summary.html

http://www.mozilla.org/rhino/tutorial.html

http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html



You can simply use the java methods / objects from JavaSCript side:

http://www.mozilla.org/rhino/tutorial.html#useJava

or

http://www.mozilla.org/rhino/scriptjava.html



Regards