jakarta-bsf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Victor J. Orlikowski" <...@dulug.duke.edu>
Subject Re: how to access scripted objects?
Date Thu, 13 Feb 2003 10:11:06 GMT
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

Mime
View raw message