By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,738 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,738 IT Pros & Developers. It's quick & easy.

Java as a scripting language.

P: n/a
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.
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
William Korvine wrote:
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>.

--
Jonas Kongslund
Jul 17 '05 #2

P: n/a
William Korvine <ko*****@hotmail.com> wrote in message news:<Xn*******************************@66.185.95. 104>...

[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.

Any hints would be helpful.

William Korvine

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- ><>
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.