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 sebb <se...@gmail.com> on 2007/07/02 00:30:21 UTC

Access to declared variables from Java

I'd like to be able to pass a variable into a BSF script, allow the
script to change the value of the variable, and retrieve the changed
value when the script has finished.

I've tried:

mgr.declareBean("Message", "OK", String.class);
BSFEngine bsfEngine = mgr.loadScriptingEngine("groovy");
bsfOut=bsfEngine.eval("script", 0, 0, "Message=\"123\"");

but

mgr.lookupBean("Message");

returns the original value of the string, i.e. "OK"

The script can set the value using

bsf.registerBean("Message","123")

but this is rather messy compared with being able to do:

Message="123"

It would be nice if there was a way to access the variables themselves.

Is this possible in BSF?

S///

---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Re: Access to declared variables from Java

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
sebb wrote:
> I'd like to be able to pass a variable into a BSF script, allow the
> script to change the value of the variable, and retrieve the changed
> value when the script has finished.
>
> I've tried:
>
> mgr.declareBean("Message", "OK", String.class);
> BSFEngine bsfEngine = mgr.loadScriptingEngine("groovy");
> bsfOut=bsfEngine.eval("script", 0, 0, "Message=\"123\"");
>
> but
>
> mgr.lookupBean("Message");
>
> returns the original value of the string, i.e. "OK"
>
> The script can set the value using
>
> bsf.registerBean("Message","123")
>
> but this is rather messy compared with being able to do:
>
> Message="123"
>
> It would be nice if there was a way to access the variables themselves.
>
> Is this possible in BSF?
Well, this would be a feature of the BSF engine for your language
(accessing, changing, storing Java objects in the BSF registry).

Depending on the scripting language at hand making BSF registry entries
available transparently to your programming language as if they were
variables defined in the context of your script code could be
easy/simple (e.g. because it already supports Java bindings one way or
the other) or complicated (has no clues of Java at all, hence the
bridging/interfacing support needs to be created).

HTH,

---rony



---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org