[IronPython] (ironclad) is it possible to get the current ScriptEngine?

Dino Viehland dinov at microsoft.com
Thu Nov 20 20:11:34 PST 2008


Oh, and instead of ScriptSource you can use SourceUnit.  You might find there's too much stuff marked internal w/ SourceUnit so any issues you run into here would be interesting to hear.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of William Reade
Sent: Thursday, November 20, 2008 9:50 AM
To: Discussion of IronPython
Subject: Re: [IronPython] (ironclad) is it possible to get the current ScriptEngine?

It seems I don't actually use the engine for very much, so this sounds
pretty plausible -- context.SystemState can replace Python.GetSysModule,
and HostingHelpers.GetLanguageContext goes away entirely :).

However, I can't see any obvious way to create a ScriptScope
(engine.CreateScope) or a ScriptSource
(engine.CreateScriptSourceFromString) -- even if I just dupe IronPython
code, it seems I'll still need an actual PythonEngine to construct them.
Am I missing something obvious?

William Reade wrote:
> Thanks Dino -- I'll see what I can do with that :)
>
> Dino Viehland wrote:
>> It's not really possible to get back to the ScriptEngine - but you
>> also probably don't need to.  You probably want to get back to the
>> LanguageContext(PythonContext)/ScriptDomainManager and work with
>> those directly.  ScriptEngine/ScriptRuntime are wrappers around those
>> which expose the friendly API and provide the easy remoting features.
>>
>> You can get to the LanguageContext via a CodeContext.  You can get a
>> CodeContext by just defining it as the 1st parameter on a .NET method
>> which we'll be calling at some point.
>>
>> For example our ModuleLoader class for pre-compiled code has a
>> load_module method which receives a CodeContext.  It then uses it to
>> call back into the current PythonContext and create a new module.
>>
>> -----Original Message-----
>> From: users-bounces at lists.ironpython.com
>> [mailto:users-bounces at lists.ironpython.com] On Behalf Of William Reade
>> Sent: Thursday, November 20, 2008 5:36 AM
>> To: Discussion of IronPython
>> Subject: [IronPython] (ironclad) is it possible to get the current
>> ScriptEngine?
>>
>> Hi all
>>
>> At the moment, when a user types 'import ironclad', I create a new
>> ScriptEngine and set that up to allow .pyd imports; I then abuse
>> path_hooks to use the new engine to do the imports, and copy them into
>> the original engine's sys.modules. Clearly, this is evil and wrong on
>> any number of levels, but so far it's been (just barely) good enough.
>>
>> However, if I can find out which ScriptEngine is executing the code (so
>> I can pass that into the Python25Mapper), I can greatly simplify
>> ironclad.py and, hopefully, solve another user's problem (which, I
>> believe, is related to sys.path not being shared between the two engines
>> (quite rightly so, ofc ;))).
>>
>> So: is there any way I can get a reference to the executing engine from
>> within IronPython code? It feels as if it should be possible, but
>> whenever I look into it I end up chasing my tail...
>>
>> William
>> _______________________________________________
>> 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
>>
>>
>
> _______________________________________________
> 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


More information about the Users mailing list