There are some behaviours built into the core program, but these are very limited,
repetitive behavours. These use VRML type Sensors and Interpolators. These work
by sending events between the beans.
There is a need to add much more general purpose behaviours. It seems to me
that the best way to do this is to support a scripting language in the program.
There seem to be a number of such programs availible, see below, so it seems
silly to try to re-invent the wheel.
Whatever scripting language is chosen it needs to be able to.
- Set and read the bean properties.
- Call the bean methods
- Generate bean events.
- Be triggered by the bean events.
- The scripts need to be stored with the program (for example in XML format)
or loaded interactively by the user
- needs to be open source so that we can be sure that it will always be available,
and bugs can be fixed.
Examples of how this might be used: say you were writing a 3D game, when there
was a collision between two objects, this would trigger a script which would
alter the scores and start an explosion secuence.
Another example might be to drive an animation sequence.
JPython
JPython looks like a good possibility, in order to try it out I have added JPython
support to
mjbWorld_beta307. If you select
RunJPython under the FILE menu it runs the following method:
public void RunJPython(){
try {
String line;
FileReader fr;
BufferedReader br;
File selectedFile = null;
PythonInterpreter interp = new PythonInterpreter();
javax.swing.JFileChooser fileChooser = new javax.swing.JFileChooser();
if (directory == null) directory = new File("//C:");
int returnvalue = fileChooser.showDialog(null,null);
if (returnvalue == javax.swing.JFileChooser.APPROVE_OPTION) {
directory = fileChooser.getCurrentDirectory();
selectedFile = fileChooser.getSelectedFile();
fr = new FileReader(selectedFile);
br = new BufferedReader(fr);
do {
line=br.readLine();
if (line != null) {
statusMessage(line);
interp.exec(line);
}
} while (line != null);
}
fileChooser.setVisible(false);
} catch (Exception e) {
System.out.println("mjbFrame.RunJPython error: " + e.toString());
}
return;
}
The only problem is that JPython is not Java, so it would be a new language
for the users to learn.
Further details at:
http://www.jpython.org/
JPython is an implementation of the high-level, dynamic, object-oriented language
Python seamlessly integrated with the Java platform and certified as 100% Pure
Java. JPython is freely available for both commercial and non-commercial use
and is distributed with source code. JPython supports embedded scripting - Java
programmers can add the JPython libraries to their system to allow end users
to write simple or complicated scripts that add functionality to the application.
Since JPython is certified 100% Pure Java, it can be added to an application
without fear of compromising its ability to run on all Java platforms.
Rhino
http://www.mozilla.org/rhino/index.html
Rhino is an implementation of JavaScript written entirely in Java. It gets
its name from the animal on the cover of the O'Reilly book about JavaScript.
The Rhino project was started at Netscape in Fall 1997. At the time, Netscape
was planning to produce a version of Navigator written entirely in Java and
so it needed an implementation of JavaScript written in Java. When Netscape
stopped work on "Javagator", as it was called, somehow Rhino escaped
the axe (rumor had it that the executives "forgot" it existed). Since
then, a couple of major companies (including Sun) have licensed Rhino for use
in their products and paid Netscape to do so, allowing us to continue work on
it. Now Rhino is planned to be part of several server products from Netscape
as well.
Originally, Rhino compiled all JavaScript code to Java bytecodes in generated
classfiles. This produced the best performance (often beating the C implementation
of JavaScript when run on a JIT), but suffered from two faults. First, compilation
time was long since generating Java bytecodes and loading the generated classes
was a heavyweight process. Also, the implementation effectively leaked memory
since most JVMs don't really collect unused classes or the strings that are
interned as a result of loading a class file.
So in Fall of 1998, Rhino added an interpretive mode. The classfile generation
code was moved to an optional, dynamically-loaded package. Compilation is faster
and when scripts are no longer in use they can be collected like any other Java
object.
We've wanted to put Rhino in Mozilla ever since mozilla.org was started, but
have been limited by the contracts we signed with licensees. Just recently we
received approval from our licensees to make Rhino publicly available as free
source, but they requested that we hold back classfile generation for the time
being. Considering that Rhino probably wouldn't have existed were it not for
their support, I think it's a reasonable request. Most of what makes Rhino appealling
can be had even without classfile generation, which is primarily a performance
enhancement.
BeanShell
BeanShell is a small, free, embeddable, Java source interpreter with object scripting
language features, written in Java. BeanShell executes standard Java statements
and expressions, in addition to obvious scripting commands and syntax
see http://www.beanshell.org/
Bean Scripting Framework BSF
For more information about BSF, see http://www.alphaworks.ibm.com/
Bean Markup Language' (BML)
. (www.alphaworks.ibm.com)
Other possible script languages:
http://grunge.cs.tu-berlin.de/~tolk/vmlanguages.html
Adding New tools
We also be able to dynamically add new tools, wizards, etc. to the program.
Again this should be done by plugging in a general purpose scripting language.
These wizards would be assined to menu items and stored as scripts when the
program is saved.
This site may have errors. Don't use for critical systems.
Copyright (c) 1998-2008 Martin John Baker - All rights reserved.