You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-user@jakarta.apache.org by "Victor J. Orlikowski" <vj...@dulug.duke.edu> on 2003/02/13 11:11:06 UTC

Re: how to access scripted objects?

On Fri, Jan 31, 2003 at 05:35:49PM +0100, Oliver.Kowalke@freudenberg.de wrote:
> I've no idea how to access scripted objects (JavaScript). My java test app
> looks like this:
> 
> BSFManager mgr = new BSFManager();
> BSFEngine engine = mgr.loadScriptingEngine("javascript");
> FileReader in = new FileReader("c:/temp/test.js");
> String script = IOUtils.getStringFromReader( in);
> 	
> Object obj = engine.eval("", -1, -1, script);
> 
> The JavaScript test.js looks like this :
> 
> var g_test = new Array();
> function f()
> {
>    g_test[1] = new Object();
>    g_test[1].str = 'Y1Z1';
>    g_test[2] = new Object();
>    g_test[2].str = 'Y1Z2';
> }
> 
> The variable 'g_test' will be initialized by function 'f()'.
> I don't know how to invoke 'f()' and how to access 'g_test'.
> 

1) You should invoke f() either from within your script or via the
call() method.

2) To access g_test, you may want to use an expression. I will
warn you, however, that if you are using Rhino, you will run into
a large wart w.r.t. array handling.

Hope that helps,
Victor
-- 
Victor J. Orlikowski   | The Wall is Down, But the Threat Remains!
==================================================================
orlikowski@apache.org  | vjo@dulug.duke.edu | vjo@us.ibm.com