Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Scripting engine in Java - Do We Really Need Them?

Started by HellCreator Feb 15, 2005 at 2:12 AM 15 replies 2.6k views
Original Post
HellCreator
HellCreator
Question to Java Guru! Need some lightweidth script engine like lua to embed into java applet and app OR may be java have one ? I know about using javac via System at run time and then loadin via reflection but it is imposible in applet. Realy do I need this stuff ? Just because recompilation less - YES! Found this http://www.beanshell.org comments if any? [Edited by - HellCreator on February 15, 2005 2:33:47 AM]
Can't be root?Reboot!mount -r /home/hell
markr
markr
Well, you never really "need" a scripting engine because it's possible to do anything you can with a scripting engine, with precompiled code.

You might find it advantageous under some circumstances to use a scripting engine though.

Regarding using javac in an applet, no you can't, but you *can* run a server-side script which runs javac and returns the class file(s) (perhaps in a jar).

You should look at Rhino (&#106avascript engine written in Java, uses reflection) to achieve what I think you're trying to.<br><br>Mark
Shabadoo
Shabadoo
Having scriptable events/code makes the software development cycle easier. You can adjust a script without having to recompile the entire application. Once you have finalised the script you can either hard code it or leave it scripted. Scripting also allows for a lot of extensibility in a system as well.


The best scripting engine I have found for use in Java is Beanshell (which you already found), as it integrates seamlessly.

[edit] spelling
Luctus
Luctus
You could try Jython
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams
CaptainJester
CaptainJester
Or you could just use XML. You can store anything you want in XML, so it would be a good replacement for a scripting engine. Plus Java provides an API for loading XML already.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
HellCreator
HellCreator
Thanks for all replays
I found verry interesting Rhino and Beanshell.
The mission is - do not force the end user to dowload and ah to install libraries required to app or applet and do not doing any server side action because engine may be oriented for runing on client mashine only without installing any servers localy.
Can't be root?Reboot!mount -r /home/hell
HellCreator
HellCreator
Quote:
Original post by CaptainJester
Or you could just use XML. You can store anything you want in XML, so it would be a good replacement for a scripting engine. Plus Java provides an API for loading XML already.

but - do java provide proccessing stored data as class object or class function
it is what the scripting do?
Can't be root?Reboot!mount -r /home/hell
Luctus
Luctus
Quote:
Original post by HellCreator
The mission is - do not force the end user to dowload and ah to install libraries required to app or applet and do not doing any server side action because engine may be oriented for runing on client mashine only without installing any servers localy.

In case you decided against jython because of those reasons you might want to reconsider. Jython doesn't put any prerequisies on client or server, you just have to pack a 700k library together with your app/applet.

Besides, python is an awesome language =)
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams
CaptainJester
CaptainJester
Quote:
Original post by HellCreator
but - do java provide proccessing stored data as class object or class function
it is what the scripting do?


I believe you can do that with reflection. However, I am not sure I understand what you are saying. Can you explain a bit more?
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
HellCreator
HellCreator
Quote:
Original post by CaptainJester
Quote:
Original post by HellCreator
but - do java provide proccessing stored data as class object or class function
it is what the scripting do?


I believe you can do that with reflection. However, I am not sure I understand what you are saying. Can you explain a bit more?


i mean the maner just how it is lua does for C
Can't be root?Reboot!mount -r /home/hell
CaptainJester
CaptainJester
Quote:
Original post by HellCreator
Quote:
Original post by CaptainJester
Quote:
Original post by HellCreator
but - do java provide proccessing stored data as class object or class function
it is what the scripting do?


I believe you can do that with reflection. However, I am not sure I understand what you are saying. Can you explain a bit more?


i mean the maner just how it is lua does for C


I have never used Lua or any other scripting engine. You would have to tell me what Lua does.

I assume you want to provide data to the game that affects what objects are placed where, what enemies are around, the abilities and locations of those objects and enemies, etc...

If this is the case, you can do all that with XML and Reflection. Plus, this way you don't have to add extra libraries, you can just use what is provided with the Java core libraries.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
HellCreator
HellCreator
To CaptainJester
Let say in app You have
int a=1;int b=2;int c;scriptengineVM.populate(a);scriptengineVM.populate(b);scriptengineVM.populate(c);//and scriptString script="c=a+b";//after call to scriptengineVM.execute(script);//here I expect to c=3

second variant
String script="int d=1,e=2,f;f=d+e;"scriptengineVM.execute(script);//then in my app I can do some like thisint f=scriptengineVM.getglobal("f");

I think idea is simple
the script can be placed in some text file
variables can be objects and even classes "Lightweight classes"

Lua may be compiled with Your app or just linked
Can't be root?Reboot!mount -r /home/hell
HellCreator
HellCreator
To Anonymous Poster
Thanks for supporting my vew
Finaly I will stoping at Beanshell :) For my current project
but to the future I think to write one mine may be just to get some experience.
About Your suggestion its seems like you need foreach variant wrap function
and foreach posible script function tons of presets or combinations hardcoded anyway,it is seems to me like BV or TK tecnique of "incapsulatin private variables or functions or may be predefined event driven stile" in some cases You right it may be enougth well but in real engine this tip can be aplied only to adjust and procceed KNOWN at compile time variables and functions.
correct me if I missed something.
Can't be root?Reboot!mount -r /home/hell

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.