[IronPython] Publishing a Module when Embedding

Michael Foord fuzzyman at voidspace.org.uk
Thu Jul 10 18:15:34 CEST 2008


Dino Viehland wrote:
> It's a little confusing but we are actually exposing Scope objects - not ScriptScope objects.  The DLR APIs are separated into two halves - the hosting API half and the language API half.  The hosting API objects are all remotable and expose the APIs which are needed for hosting.  The language API half are all appdomain bound and expose the API that language implementers need to see.  IronPython actually adds extension methods to both ScriptScope and Scope so they both work like modules but Scope has more functionality such as a correct __repr__, __new__, etc...
>
> You can either new up a Scope object directly or if you have a ScriptScope you can call HostingHelpers.GetScope.
>   

:-)

ScriptScopes are more convenient to work with, so I'll turn them into a 
Scope when I publish them onto the runtime.

Thanks

Michael
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
> Sent: Thursday, July 10, 2008 4:44 AM
> To: Discussion of IronPython
> Subject: Re: [IronPython] Publishing a Module when Embedding
>
> Michael Foord wrote:
>   
>> Dino Viehland wrote:
>>     
>>> You can just expose a DLR Scope object directly - which is what
>>> IronPython does for modules internally.
>>>
>>>       
>> Bah, damn - I meant to try that before posting and then forgot!
>>     
>
> Hmmm... although from inside Python code run in the engine you can still
> tell that it is a ScriptScope and not a 'real' module. I'm pretty sure
> that internally IronPython *is* using PythonModule.
>
> Not that it is a problem, publishing ScriptScopes works fine - it would
> be *nice* to have access to the same API that IP uses for publishing
> modules, but not essential.
>
> Michael
>
>   
>> Thanks
>>
>> Michael
>>
>>
>>     
>>> The name PythonModule is unfortunately a little confusing - it's
>>> actually a PythonScopeExtension where we can store additional data
>>> about the Scope (e.g. if import clr has occurred). We'll lazily
>>> create the PythonModule and associate it with the Scope if we need it.
>>>
>>> -----Original Message-----
>>> From: users-bounces at lists.ironpython.com
>>> [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
>>> Sent: Tuesday, July 08, 2008 1:43 PM
>>> To: Discussion of IronPython
>>> Subject: [IronPython] Publishing a Module when Embedding
>>>
>>> Hello all,
>>>
>>> I've been looking at writing some examples of publishing a module in an
>>> embedded scenario.
>>>
>>> The straightforward example (which also appears in the DLR hosting spec)
>>> is to just publish an *object*:
>>>
>>>           ScriptRuntime _runtime = ScriptRuntime.Create();
>>>             _runtime.Globals.SetVariable("ModuleName", someObject);
>>>
>>> What I *really* want to do is to create a PythonModule from a dictionary
>>> of objects and publish that into the runtime globals.
>>>
>>> Creating a populated PythonModule seems to be problematic. The useful
>>> overload of PythonCOntext.CreateModule (that takes 4 arguments) isn't
>>> public (internal) - I can't see how to populate the module once I've
>>> created one.
>>>
>>> There is also an internal constructor to PythonModule that takes a
>>> Scope. These seem to be the routes taken by the importer.
>>>
>>> You can't publish a dictionary (well - except as a dictionary).
>>>
>>> How can I create and populate a PythonModule from C#?
>>>
>>> Michael Foord
>>>
>>> --
>>> http://www.ironpythoninaction.com/
>>> http://www.voidspace.org.uk/
>>> http://www.trypython.org/
>>> http://www.ironpython.info/
>>> http://www.theotherdelia.co.uk/
>>> http://www.resolverhacks.net/
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at lists.ironpython.com
>>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>> _______________________________________________
>>> Users mailing list
>>> Users at lists.ironpython.com
>>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>>
>>>       
>>     
>
>
> --
> http://www.ironpythoninaction.com/
> http://www.voidspace.org.uk/
> http://www.trypython.org/
> http://www.ironpython.info/
> http://www.theotherdelia.co.uk/
> http://www.resolverhacks.net/
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.theotherdelia.co.uk/
http://www.resolverhacks.net/




More information about the Ironpython-users mailing list