[IronPython] Referencing extension modules from hosting
Dino Viehland
dinov at microsoft.com
Thu Mar 18 17:42:51 CET 2010
Jeff wrote:
> When using a C# PythonModule, there seem to be two ways to load it:
> from script using clr.AddReference and into the console by dropping it
> into the DLLs folder. However, there doesn't seem to be a
> straightforward way to load them in a hosting scenario.
>
> The best way I've found is the following:
>
> string zlibModule = "IronPython.Zlib.dll"
> object addRef = engine.GetClrModule().GetVariable("AddReference");
> Assembly zlib = Assembly.LoadFile(zlibFile);
> engine.Operations.Invoke(addRef, zlib);
>
> It's not terribly difficult to write, but it would be nice to have an
> extension method on ScriptEngine that did it.
I think ScriptRuntime.LoadAssembly should do this as well and is simpler.
>
> In a similar vein, it would be nice if the engine could scan the
> current AppDomain for assemblies that contain PythonModules - this
> would be useful when running under ASP.NET, as it references an
> assemblies in its bin/ folder, and having them automatically available
> would be handy.
I'm not sure this one is actually possible - I don't think there's any
way to enumerate loaded assemblies.
>
> Finally, it would be nice to have an extension method on ScriptScope -
> ImportModule? - that did the equivalent of
>
> scope.SetVariable("zlib", scope.Engine.ImportModule("zlib"));
>
> If these suggestions are useful I'll create issues for them.
This one sounds like a good idea.
>
> - Jeff
>
> P.S. These are the sorts of things it would be nice to be able to
> contribute patches for.
I agree :(
More information about the Ironpython-users
mailing list