views:

25

answers:

1

I'm writing a C# client application which is intended to have strong support for customisation via scripting, and I have chosen IronPython as my target scripting language. I would like to keep the user's code in the application's database with the rest of its state, but I need the user to be able to split their scripts into files and modules.

How can I configure the IronPython engine so that it will use strings (with corresponding virtual paths) as the source for imports, rather than specifying a directory in the user's filesystem? Is this possible?

+1  A: 

You need to subclass the PlatformAdaptationLayer class and implement the "file system" calls. IronPython will then go to the PAL to do I/O for the files. This also involves implementing a ScriptHost which returns the type for the PAL. A good example of this is the Silverlight host which redirects file I/O to a XAP file.

If you browse the IronPython source on IronPython.CodePlex.com you'll find the Silverlight host in IronPython_Main\Hosts\Silverlight\Microsoft.Scripting.Silverlight.

Dino Viehland