[IronPython] Hosting API and PlatformAdaptationLayer

Michael Foord fuzzyman at voidspace.org.uk
Tue Jun 10 13:59:48 PDT 2008


Interesting - thanks.

Michael

Jimmy Schementi wrote:
> For Silverlight, a custom PAL is needed to override methods like "FileExists", "LoadAssemblyFromPath", etc, since Silverlight should look inside the XAP file when anything that assumes access to the file system is used.
>
> The fact that we have a custom PAL in Silverlight a little strange, as we should support hosting the DLR in C# Silverlight apps by just having the assembles build with Silverlight, but if you can't change the DLR code and want a different platform behavior, overriding the PAL is the way to go.
>
> ~js
>
>   
>> -----Original Message-----
>> From: users-bounces at lists.ironpython.com [mailto:users-
>> bounces at lists.ironpython.com] On Behalf Of Michael Foord
>> Sent: Tuesday, June 10, 2008 1:16 PM
>> To: Discussion of IronPython
>> Subject: Re: [IronPython] Hosting API and PlatformAdaptationLayer
>>
>> What's the use case for doing this?
>>
>> Michael
>>
>> Jimmy Schementi wrote:
>>     
>>> The public API to do this is ScriptRuntimeSetup.HostType; an example
>>>       
>> of using this is in Silverlight. Take a look at
>> Microsoft.Scripting.Silverlight/BrowserPAL.cs and
>> Microsoft.Scripting.Silverlight/BrowserScriptHost.cs. Here's the
>> basics:
>>     
>>> class YourPAL : PlatforAdaptationLayer {
>>>   static readonly YourPAL PAL = new YourPAL();
>>>   ...
>>> }
>>>
>>> class YourScriptHost : ScriptHost {
>>>   ...
>>>
>>>   public override PlatformAdaptationLayer PlatformAdaptationLayer {
>>>     get {
>>>       return YourPAL.PAL;
>>>     }
>>>   }
>>> }
>>>
>>> // In code that hosts the DLR:
>>> ScriptRuntimeSetup setup = new ScriptRuntimeSetup(true)
>>> setup.HostType = typeof(YourScriptHost)
>>> ScriptRuntime runtime = ScriptRuntime.Create(setup)
>>> ...
>>>
>>> Make sense?
>>> ~Jimmy
>>>
>>>
>>>       
>>>> -----Original Message-----
>>>> From: users-bounces at lists.ironpython.com [mailto:users-
>>>> bounces at lists.ironpython.com] On Behalf Of Orian, Helmut
>>>> Sent: Tuesday, June 10, 2008 4:00 AM
>>>> To: users at lists.ironpython.com
>>>> Subject: [IronPython] Hosting API and PlatformAdaptationLayer
>>>>
>>>> At the moment I am hosting IronPython and IronRuby using the sources
>>>> from the Silverlight2beta1 SDK which I recompiled to work against
>>>>         
>> .NET
>>     
>>>> 2.0 because it is the latest build of the DLR I found where both
>>>> projects work with a common Microsoft.Scripting.dll.
>>>>
>>>> We have a client-server architecture and all our config-files and
>>>>         
>> other
>>     
>>>> script language files (like xsl and some own languages :-) are
>>>>         
>> stored
>>     
>>>> and versioned in our central application server instead of a
>>>>         
>> harddisk.
>>     
>>>> For the initial python script I want to execute this was no problem,
>>>> but
>>>> to get the import statement of python ('require' in ruby) to work I
>>>> implemented a class deriving from
>>>> Microsoft.Scripting.PlatformAdaptationLayer. This implementation
>>>>         
>> worked
>>     
>>>> perfectly for me, but I have not found a way to bootstrap
>>>>         
>> ScriptRuntime
>>     
>>>> and ScriptHost with my implementation by using the current public
>>>>         
>> API
>>     
>>>> in
>>>> Microsoft.Scripting.
>>>>
>>>> I had to use an own implementation derived from ScriptHost to inject
>>>>         
>> my
>>     
>>>> derived PlatformAdaptationLayer instance with (ugly) reflection into
>>>> the
>>>> ScriptRuntime.
>>>>
>>>> It would be nice if I could set/use my derived
>>>>         
>> PlatformAdaptationLayer
>>     
>>>> instance by public API.
>>>>
>>>>
>>>> Thanks,
>>>> Helmut
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>>         
>> ---
>>     
>>>> ----
>>>>
>>>>  An- und Abmeldung zur SCHEMA Mailingliste unter
>>>> http://www.schema.de/mail
>>>>
>>>> --------------------------------------------------------------------
>>>>         
>> ---
>>     
>>>> ----
>>>>
>>>>
>>>> _______________________________________________
>>>> 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.theotherdelia.co.uk/
>> http://www.voidspace.org.uk/
>> http://www.ironpython.info/
>> 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.theotherdelia.co.uk/
http://www.voidspace.org.uk/
http://www.ironpython.info/
http://www.resolverhacks.net/



More information about the Users mailing list