On Mon, Nov 22, 2010 at 3:21 PM, Ian Stevens <[email protected]> wrote:
> If you do not want to affect the top-level scope, you can create a new
> scope.
I *thought* that's what I was doing. My code is a bit different. I do this:
Scriptable scope = context.initStandardObjects(this);
while you do this:
> >>> s = c.initStandardObjects()
>
I have some global functions I want to expose attached to "this". So "this"
is a ScriptableObject and I then call:
String[] names = { "logInfo", "logWarning", "logError" };
defineFunctionProperties(names, this.getClass(), ScriptableObject.DONTENUM);
which makes the logging functions available to the scripts. If I do this:
Scriptable scope = context.initStandardObjects();
then "logInfo" will not be found. So it seems I'm creating a top-level scope
that I'm reusing across script runs. Can anyone confirm this? Changing my
eval call like so:
context.evaluateString(scope, javaScript, "<" + scriptedEntityId + ">", 1,
null);
doesn't have any effect which makes sense since I created "scope" based on
"this". Perhaps my problem is really, how to expose global functions to the
script. Can someone give me some examples of
using defineFunctionProperties()?
I do plenty of this:
ScriptableObject.putProperty(scope, "MyClass", new NativeJavaClass(scope,
blah.MyClass.class));
which puts the static methods of MyClass on a property
(MyClass.myStaticMethod()) but I'm not sure of another way to put a
top-level method in the scope.
Thanks.
--
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
http://www.opentempo.com
mailto:[email protected]
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino