How to set up dynamic import when placing IronPython?

I am writing a C # client application that should have strong support for customization through scripts, and I have chosen IronPython as my target scripting language. I would like to save the user code in the application database with the rest of its state, but I need the user to be able to split his scripts into files and modules.

How can I configure the IronPython engine to use strings (with corresponding virtual paths) as the source to import, instead of specifying a directory in the user file system? Is it possible?

+3
source share
1 answer

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

If you are viewing IronPython's source on IronPython.CodePlex.com, you will find the Silverlight host in IronPython_Main \ Hosts \ Silverlight \ Microsoft.Scripting.Silverlight.

+3
source

Source: https://habr.com/ru/post/1754971/


All Articles