[IronPython] ScriptEngine.GetRegisteredExtensions()

Ben Hall ben2004uk at googlemail.com
Thu Jun 12 00:32:31 CEST 2008


Oh I see!!! Just wrote a quick sample and I think that will be fine.
Not as easy as before, but should still be ok.

Thanks for your help.

Ben


On Wed, Jun 11, 2008 at 11:22 PM, Curt Hagenlocher <curt at hagenlocher.org> wrote:
> When you create a ScriptRuntime, you can pass in a ScriptRuntimeSetup object
> that specifies additional language providers to load.  Perhaps this is less
> automatic than you'd like, but if you were going to load those assemblies
> into your appdomain anyway, it's just taking the extra step of looking in
> that assembly for a class derived from LanguageContext.
>
> On Wed, Jun 11, 2008 at 2:53 PM, Ben Hall <ben2004uk at googlemail.com> wrote:
>>
>> Oh!
>>
>> Can't remember the reason why I went for the type over the file
>> extension.  But anyway, what I'm doing it manually loading in the
>> language assemblies, finding the LanguageContext type (I know the name
>> from an XML config file) and passing that in.
>>
>> I guess I could just have the file extension in the XML. My only
>> concern is that when other languages come along, how do they register
>> their file extension with my ScriptRuntime?
>>
>> I've loaded their assemblies into my appdomain, is there any
>> additional logic required?  Using the type, I was confident this
>> wouldn't be a problem (guess thats why I went that route).
>>
>> It tries to get the language context from _languageIds, which is
>> populated via RegisterLanguageContext. That seems to get called via
>> the _languageProviders collection.  This seems to have all cheeky
>> hardcoded everything I was passing in dynamically (well, based on the
>> XML).
>>
>> I can't see how I could dynamically load in a DLR language and create
>> an engine just via the file extension. If there is a way, please let
>> me know.
>>
>> I hope that all makes sense (wrote while debugging DLR code)
>>
>> Thanks
>>
>> Ben
>>
>>
>> On Wed, Jun 11, 2008 at 10:33 PM, Curt Hagenlocher <curt at hagenlocher.org>
>> wrote:
>> > The overload of GetEngine that you're using is slated to go away. Is
>> > there
>> > functionality you get out of doing it that way that you don't get by
>> > using
>> > the language code or file extension?
>> >
>> > On Wed, Jun 11, 2008 at 2:17 PM, Ben Hall <ben2004uk at googlemail.com>
>> > wrote:
>> >>
>> >> Sorry - my code wasn't very helpful.
>> >>
>> >> The above code works fine, however I am creating the engine based on
>> >> the type. The code demostrates the problem:
>> >>
>> >>            ScriptRuntime runtime = ScriptRuntime.Create();
>> >>            ScriptEngine engine =
>> >> runtime.GetEngine(typeof(IronPython.Runtime.PythonContext));
>> >>            foreach (string s in engine.GetRegisteredExtensions())
>> >>            {
>> >>                System.Console.WriteLine(s);
>> >>            }
>> >>
>> >> Thanks
>> >>
>> >> Ben
>> >>
>> >> On Wed, Jun 11, 2008 at 9:22 PM, Curt Hagenlocher
>> >> <curt at hagenlocher.org>
>> >> wrote:
>> >> > I can't see into any of the helpers you've defined.  What do you get
>> >> > if
>> >> > you
>> >> > cut this down to the smallest possible program?
>> >> >
>> >> > public static void Main() {
>> >> >     ScriptRuntime runtime = ScriptRuntime.Create();
>> >> >     ScriptEngine engine = runtime.GetEngine("py");
>> >> >     foreach (string s in engine.GetRegisteredExtensions()) {
>> >> >         System.Console.WriteLine(s);
>> >> >     }
>> >> > }
>> >> >
>> >> > On Wed, Jun 11, 2008 at 12:23 PM, Ben Hall <ben2004uk at googlemail.com>
>> >> > wrote:
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> I have been using the latest release of the DLR (the one from
>> >> >> yesterday) but the behaviour of GetRegisteredExtensions() seems to
>> >> >> have changed (or is broke).
>> >> >>
>> >> >> I've got this test:
>> >> >>
>> >> >>        [Test]
>> >> >>        public void GetSaveFilter_RegisteredTypes_String()
>> >> >>        {
>> >> >>            string expected = "IronPython 2.0 Beta|*.py";
>> >> >>            LanguageSettings python =
>> >> >> Helper.CreateIronPythonSettings();
>> >> >>            DLREngineFactory factory = new DLREngineFactory();
>> >> >>            ScriptEngine engine = factory.CreateEngine(python);
>> >> >>
>> >> >>            EngineInformation info = new EngineInformation(engine);
>> >> >>            string actual = info.GetSaveFilter();
>> >> >>            Assert.AreEqual(expected, actual);
>> >> >>        }
>> >> >>
>> >> >> With IP Beta 2, this worked fine, but since upgrading it now fails.
>> >> >> The code is this:
>> >> >>
>> >> >>        public string GetSaveFilter()
>> >> >>        {
>> >> >>            string filter = string.Empty;
>> >> >>            foreach (string ext in Engine.GetRegisteredExtensions())
>> >> >>            {
>> >> >>                filter += string.Format("{0}|*{1}",
>> >> >> Engine.LanguageDisplayName, ext);
>> >> >>            }
>> >> >>
>> >> >>            return filter;
>> >> >>        }
>> >> >>
>> >> >> >From what I can tell, the code is dropping into
>> >> >> GetRegisteredFileExtensions(LanguageContext context)  which does a
>> >> >> check to see if the LanguageContext is null, but it always seems to
>> >> >> be
>> >> >> null.
>> >> >> if (kvp.Value.LanguageContext == context) {
>> >> >>                        res.Add(kvp.Key);
>> >> >> }
>> >> >>
>> >> >> Can anyone else confirm this?
>> >> >>
>> >> >> Its the same for GetRegisteredIdentifiers().
>> >> >>
>> >> >> Thanks
>> >> >>
>> >> >> Ben
>> >> >> Blog.BenHall.me.uk
>> >> >> _______________________________________________
>> >> >> 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
>> >
>> >
>> _______________________________________________
>> 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 Ironpython-users mailing list