[IronPython] How to nest ScriptScopes

Dino Viehland dinov at exchange.microsoft.com
Fri May 9 18:58:52 CEST 2008

It's not really intended that you nest the scopes yourself - usually the scopes only get nested when you have a closure.  And then we'll burn references into the parent scopes tuple's directly so we might not even see nested variables (although in some cases we might due a full runtime lookup and see them).

Instead of nesting them can you have a ScriptScope that contains other ScriptScope's?  In other words your inner most level is just a collection of ScriptScope's which you publish under some well known name into the outer level.  Then users can dot through them:

outermost = new ScriptScope();
innermost = new ScriptScope();
innermost.SetVariable("somevalue", 3);
outermost.SetVariable("next", innermost);

then run in outermost.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Marty Nelson
Sent: Friday, May 09, 2008 9:52 AM
To: users at lists.ironpython.com
Subject: [IronPython] How to nest ScriptScopes

I've gone over the 2.0 B2 source code, but I'm not clear how I might create nested ScriptScopes using the API in C#

One of the tests in EngineTests.cs uses "from published_context_test import x" but this is only one variable, and I'd rather do it from the C# setup side anyway.

I noticed that Scope, which ScriptScope contains, has the ability to take a parent Scope, but I'm not clear how I would do this.  It seems not to be exposed via ScriptScope.

We are using IronPython as a script based extension mechanism for our C# application, my interest is to have a set of established scopes that I can populate with the variables of current application objects at the appropriate level for the current script.


Marty Nelson
Notice: This e-mail message, together with any attachments, contains
information of Symyx Technologies, Inc. or any of its affiliates or
subsidiaries that may be confidential, proprietary, copyrighted,
privileged and/or protected work product, and is meant solely for
the intended recipient. If you are not the intended recipient, and
have received this message in error, please contact the sender
immediately, permanently delete the original and any copies of this
email and any attachments thereto.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080509/c8e47b54/attachment.html>

More information about the Ironpython-users mailing list