Norris Boyd wrote:
> On Jun 17, 9:40 am, chris idr <[EMAIL PROTECTED]> wrote:
>
>> Attila Szegedi wrote:
>>
>>> Just use ScriptableObject.putProperty()
>>>
>>> i.e. if your top-level scope (in Java) is a variable "ScripableObject
>>> topScope", then
>>>
>>> ScriptableObject.putProperty(topScope, "someName", myJavaObject);
>>>
>>> will make the myJavaObject available under variable name "someName" in
>>> your script's top level scope.
>>>
>>> Attila.
>>>
>>> On 2008.06.17., at 13:24, chris idr wrote:
>>>
>>>> I'm trying to add already existing java objects to javascript, with the
>>>> right access name for predifined scripts to run on them.
>>>> But I cannot find any examples within the rhino documentation, and
>>>> example classes.
>>>>
>>>> Does any have experience of this?
>>>> or if im being dumb please point it out.
>>>>
>>>> Cheers all
>>>>
>>>> Chris wade
>>>>
>> do you have a working example I could play with, please?
>>
>> As I have tried that line of code and the variable within the java
>> object i added, does not get changed and the moethods that should have
>> been called where not.
>>
>> Chris
>>
>
> Take a look at the embedding tutorial at
> http://www.mozilla.org/rhino/tutorial.html.
>
> --N
> _______________________________________________
> dev-tech-js-engine-rhino mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
>
>
cheers noris, I had already read through this but knowing more about it
and read it, made more sense, i didnt think it would be that simple.
It now seems to work as i want, I didnt need any of the jsGet_value()
etc, its much more simple.
for clarity all i am doing now is:-
String code = "" +
// "out.stringValue = \"string\";\n" +
"out.stringValue = out.getString();\n" +
// "out.println(out.getString());\n" +
// "out.value = 4;\n" +
// "out.setValue(28);\n" +
"out.println(\"mmmm d, yyyy \"+ new Date());";
Object wrappedOut = org.mozilla.javascript.Context.javaToJS(new
Testclass(), scope);
org.mozilla.javascript.ScriptableObject.putProperty(scope,
"out", wrappedOut);
Object result = cx.evaluateString(scope, code, "test", 1, null);
Testclass event =
(Testclass)org.mozilla.javascript.Context.jsToJava(scope.get("out",
scope), Testclass.class);
System.out.println("outjs="+event);
System.out.println("java:- ");
event.println("test");
with Testclass :-
public class Testclass {
private int value = -1;
private String stringValue = "empty";
public void println(String comment){
System.out.println(stringValue+" "+value+" comment="+comment);
}
public void setValue(int inVal){
System.out.println("Testclass.setValue()");
value = inVal;
}
public void setStringValue(String inString){
stringValue = inString;
}
public String getString(){
return "this is test String";
}
}
cheers All
Chris
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino