I have been Googling (and still am), but thought I'd just ask.
I have an application that needs a scripting language. I have
written my own interpreted language (a small subset of C++),
but am considering using Java as an alternative.
I need a hint on the following: How can I make Java use the
named objects within my application. For example, my current
language (ClearScript) might have the following code:
void foo( void )
{
Record newrec = NewRecord( 12 ); // New record of type 12.
newrec.Name = "Something"; // Change the 'Name' field of the record.
newrec.Data = Globals.Functions.Calculate();
newrec.Id = Globals.States.CurrentId++;
}
Most of these identifiers are user controlled. 'Record' is a
type that has hard-coded meaning to the application. 'NewRecord()'
is a function supplied by the application to create 'Record's.
'Calculate()' is user-written.
I would like similer code to work in Java, but I can't
find if it's possible to expose these objects to Java.
Any hints would be helpful.
William Korvine
PS: My experience with Java is minimal. I am a C++ Windows programmer.
Jonas Kongslund - 20 Nov 2003 00:35 GMT
> I need a hint on the following: How can I make Java use the
> named objects within my application. For example, my current
> language (ClearScript) might have the following code:
[snip]
> I would like similer code to work in Java, but I can't
> find if it's possible to expose these objects to Java.
You may want to take a look at <http://jakarta.apache.org/bsf/index.html>.

Signature
Jonas Kongslund
FISH - 20 Nov 2003 12:16 GMT
[snipped...]
> I would like similer code to work in Java, but I can't
> find if it's possible to expose these objects to Java.
[quoted text clipped - 4 lines]
>
> PS: My experience with Java is minimal. I am a C++ Windows programmer.
There are a number of scripting implementations in Java. Jython, for
example, is a Java version of Python. It quite cleverly merges itself
into the existing Java 'runtime', with near-seemless access to the Java
API's and any other packages. However, I personally found it a little
too large and resource hungry.
One alternative worth a look is Rhino - an old Mozilla-based project
which provides Javascript (ECMAScript) 1.5 support for Java. Although
none of the Java API's are automatically mirrored into the Javascript
'domain', there is a facility to manually map Java objects into Java-
script, making them visible to your scripts, while allowing Java to
trap/handle accesses to properties, etc. It's more work for you, but
the Jar is quite small, it appears to run at a decent speed, and
Javascript is very well known and supported on-line (important if end
users are to use the scripting facilities of your product!)
http://www.mozilla.org/rhino/
-FISH- ><