On Aug 7, 9:45 am, ynniv <[EMAIL PROTECTED]> wrote:
> > I read that the scope each script is determined by the thread where
> > you obtained the Context in. So if I want to make two different
> > virtual environments (one for cut-scenes, one for AI), I have to do it
> > in different threads?? That doesn't really make sense for what I'm
> > doing. I wish that scopes were determined by some sort of object key
> > instead of threads.
>
> It sounds like the "environment" you are talking about is the variable
> scope. Scripts that share scope objects share javascript variables.
>
> /* code */
>
> Scriptable applicationHooks; // this is your "application_hooks",
> defined elsewhere
> Scriptable sceneA;
> Scriptable logicA;
> Script updateSceneA;
> Script updateLogicA;
>
> void setup() {
> Context cx = Context.enter();
>
> cx.evaluateString(setupCodeSceneA, sceneA, "setupSceneA.js", 1,
> null);
> cx.evaluateString(setupCodeLogicA, logicA, "setupLogicA.js", 1,
> null);
>
> /* this configuration makes variables on applicationHooks visible,
> but places new properties on sceneA */
> sceneA = cx.newObject(applicationHooks);
> sceneA.setPrototype(applicationHooks);
> sceneA.setParentScope(null);
>
> logicA = cx.newObject(applicationHooks);
> logicA.setPrototype(applicationHooks);
> logicA.setParentScope(null);
>
> updateSceneA = cx.compileString(updateCodeSceneA,
> "updateSceneA.js", 1, null);
> updateLogicA = cx.compileString(updateCodeLogicA,
> "updateLogicA.js", 1, null);
>
> cx.exit();
>
> }
>
> void update() {
> Context cx = Context.enter();
> updateSceneA.exec(cx, sceneA);
> updateLogicA.exec(cx, logicA);
> cx.exit();
>
> }
>
> /* endcode */
>
> For more information, check outhttp://www.mozilla.org/rhino/scopes.html.
>
> - Vinny
And Rhino scopes are independent of threads. You don't have to have
different threads to handle different scopes.
--N
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino