On Feb 18, 10:51 am, Attila Szegedi <[EMAIL PROTECTED]> wrote:
> Sure, just add
>
> ScriptableObject.putProperty(scope, "p1", p1);
>
> to your code before you run the script with evaluateReader. Also, I
> don't think you need to use ScriptableObject.defineClass() here at
> all; it has a different intended purpose.
>
> Attila.
>
> On 2008.02.17., at 22:06, beadrsh wrote:
>
> > Hi ,
> > I have a class
> > class person{
> >    String name;
> > }
>
> > and another class wherein i create an object of person class with set
> > its member name value.
>
> > public class Test {
>
> >    public static void main(String[] args) {
> >        try {
> >            Context cx = Context.enter();
> >            person p1 = new person();
> >            p1.name = "beadar";
> >            Scriptable scope = cx.initStandardObjects();
> >            ScriptableObject.defineClass(scope, person.class);
> >            FileReader script = new FileReader("check.js");
> >            Object result = cx.evaluateReader(scope, script,"<cmd>",
> > 1, null);
> >              System.out.println(result);
> >        } catch (Exception e) {
> >            e.printStackTrace();
> >        }
> >    }
> > }
>
> > What i want to know is, is there a way in check.js where i can catch
> > hold of p1 instance where in i  can retreive its state like for ex: do
> > p1.name in the javascript.


Many thanks for the reply. I typed in the following

Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
person p1 = new person();
p1.name = "beadar";
ScriptableObject.putProperty(scope, "p1", p1);
FileReader script = new FileReader("check.js");
Object result = cx.evaluateReader(scope, script,"<cmd>", 1, null);
System.out.println(result);

and in the check.js

result = "Hello " + p1.name



but in the result it prints     "Hello undefined"     .Am i missing
something here.Any help would be greatly appreciated


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

Reply via email to