This is the primary resource you want to use for the rhino documentation:

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

The examples page there has a number of self contained code snippets that
should get you exactly what you want. The code in Rhino is different, but
nor much more complex to set up a simple example like this.

The basic thing to understand is that a Context is like your ScriptEngine,
and a Scope is the embodiment of the javascript environment (it contains the
objects, functions, variables, but is just a container that is used by a
given script).

I think the embedding tutorial will be the best place go from where you're
at now.

http://www.mozilla.org/rhino/tutorial.html
(you will probably also want to read the tutorial on Scopes and Contexts, it
took me a couple of reads to grasp fully, but it's pretty straight forward
once you've got it, and fundamental to the whole API).

The direct answer to your question regarding how to reproduce the example
code using the Rhino API can be most easily demonstrated in the basic
Runscript example also available on the site referenced above.

http://mxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript.java

Let us know if when you run into more questions from there.

Dave



-----Original Message-----
From:
dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozilla.org
[mailto:dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozill
a.org] On Behalf Of Jereme
Sent: Monday, March 02, 2009 7:16 AM
To: [email protected]
Subject: Re: Pause and Resume Script

Thanks for the reply Dave.  That is what I am finding as well.  I
found a Continuation class in the JDK classes -
(sun.org.mozilla.javascript.internal.continuations.Continuation)
although I have not had much luck implementing it.  The JDK classes do
not appear to have the ContinuationPending class which appears to be
critical in the all of the Rhino examples when I run them.

Now with the JDK classes it is very straight forward to execute a file
containing JavaScript (or a string for that matter) but with the Rhino
classes I can not find any examples showing how to do this.

For example in JDK classes:

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
engine.eval("var a=10;" +
        "var b=5;" +
        "var c=a+b;" +
        "println(c);");

// Will print 15 to the Java console when ran

How would the above code be written using the Rhino classes?
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino


_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to