M. David Peterson
2008-Feb-09 01:35 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
A recent inquiry on the Ruby.NET list brought up the question as to whether or not the ability to reference ruby libs as embedded resources is supported or will be supported via IronRuby. e.g., require ''res://assembly.dll/foo/bar'' Yes/No/Maybe? Reasons For/Against/Agnostic? -- /M:D M. David Peterson Co-Founder & Chief Architect, 3rd&Urban, LLC Email: m.david at 3rdandUrban.com | m.david at amp.fm Mobile: (206) 418-9027 http://3rdandUrban.com | http://amp.fm | http://www.oreillynet.com/pub/au/2354
John Messerly
2008-Feb-09 01:48 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
M. David Peterson:> A recent inquiry on the Ruby.NET list brought up the question as to > whether or not the ability to reference ruby libs as embedded resources > is supported or will be supported via IronRuby. e.g., > > require ''res://assembly.dll/foo/bar'' > > Yes/No/Maybe? Reasons For/Against/Agnostic?Is the embedded resource a Ruby file or something else? What is the feature used for? - John
Curt Hagenlocher
2008-Feb-09 02:00 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
On Feb 8, 2008 5:48 PM, John Messerly <jomes at microsoft.com> wrote:> M. David Peterson: > > > A recent inquiry on the Ruby.NET list brought up the question as to > > whether or not the ability to reference ruby libs as embedded resources > > is supported or will be supported via IronRuby. e.g., > > > > require ''res://assembly.dll/foo/bar'' > > Is the embedded resource a Ruby file or something else? > What is the feature used for?I imagine the idea is to make deployment more robust by putting the Ruby source somewhere that a user can''t screw up. ;) At least, that''s what *I''d* want it for... -- Curt Hagenlocher curt at hagenlocher.org
M. David Peterson
2008-Feb-09 02:06 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
On Fri, 08 Feb 2008 18:48:39 -0700, John Messerly <jomes at microsoft.com> wrote:> Is the embedded resource a Ruby file or something else?Yes, a Ruby file.> What is the feature used for?Here''s a copy of the pertinent pieces from the related thread on the Ruby.NET list. In short, for ease of redistribution of stdlib source files. On Fri, 08 Feb 2008 18:26:57 -0700, M. David Peterson <m.david at xmlhacker.com> wrote:> On Fri, 08 Feb 2008 13:33:47 -0700, chriso <chrisortman at gmail.com> wrote:>> Is there a way to bundle any required libraries into the compiled >> dll? > > You could embed a source file into the assembly and then resolve that > file internally to your code base. However, I''m not sure if there is > any officially sanctioned way as of yet to reference embedded resources > (e.g. res://assemblyname.dll/foo), though this certainly seems like > something that needs to be both considered and discussed. > > A temporary hack[1,2] _could_ be used (though I wouldn''t recommend this > for anything beyond experimentation) via creating an assembly who''s only > purpose was to return requests for embedded resources to then evaluate > the returned Ruby.String, but this would only work for a small fraction > of use-cases in which the referenced stdlib didn''t reference any other > stdlibs. In this regard there would need to be some way of indicating > to the Ruby.NET Runtime whether it should look for an embedded resource, > and if yes, where it should look. > > I would think that using the standard res://assemblyname.dll/foo/bar > would make the most sense. Anybody happen to have a sense as to how to > properly handle this? I''ll make a post to the IronRuby list to see if > they plan to provide support for embedded resources, and if so, the > syntax they plan to use. > > > [1] C# ResourceManager which returns the Ruby.String for the referenced > embedded resource. > > using System; > using System.Resources; > using System.Text; > > namespace ResourceLib > { > public class RubyStdLib > { > static Encoding m_encoding = Encoding.UTF8; > static ResourceManager manager = > Properties.Resources.ResourceManager; > > public Ruby.String getStdLib(string stdLibName) > { > return new > Ruby.String(m_encoding.GetString((byte[])manager.GetObject(stdLibName))); > } > } > } > > [2] Modified Ruby > > require ''mscorlib.dll'' > a_date = System::DateTime.new(2007, 1, 1) > puts a_date.AddYears(1).ToString() > puts ''Hello .net'' > > input = %{\ > <% high.downto(low) do |n| # set high, low externally %> > <%= n %> green bottles, hanging on the wall > <%= n %> green bottles, hanging on the wall > And if one green bottle should accidentally fall > There''d be <%= n - 1 > %> green bottles, hanging on the wall > <% end %> > } > high,low = 10, 8 > > # Beware of the horrific hack just begging to be exploited that follows. > # Beyond loading the source file directly or using the taint method is > # there a better way to handle this that''s not immediately obvious? > > require ''ResourceLib.dll'' > rm = ResourceLib::RubyStdLib.new > erb = eval(rm.getStdLib(''erb''))::ERB.new(input) > puts erb > bind = Kernel.binding > puts bind > puts erb.run(bind) > > puts ''Bye .net'' >-- /M:D M. David Peterson Co-Founder & Chief Architect, 3rd&Urban, LLC Email: m.david at 3rdandUrban.com | m.david at amp.fm Mobile: (206) 418-9027 http://3rdandUrban.com | http://amp.fm | http://www.oreillynet.com/pub/au/2354
M. David Peterson
2008-Feb-09 02:07 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
On Fri, 08 Feb 2008 19:00:26 -0700, Curt Hagenlocher <curt at hagenlocher.org> wrote:> I imagine the idea is to make deployment more robust by putting the > Ruby source somewhere that a user can''t screw up.Yup!> At least, that''s what *I''d* want it for...You and I both, Curt! :D -- /M:D M. David Peterson Co-Founder & Chief Architect, 3rd&Urban, LLC Email: m.david at 3rdandUrban.com | m.david at amp.fm Mobile: (206) 418-9027 http://3rdandUrban.com | http://amp.fm | http://www.oreillynet.com/pub/au/2354
John Messerly
2008-Feb-09 02:09 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
Curt Hagenlocher:> On Feb 8, 2008 5:48 PM, John Messerly <jomes at microsoft.com> wrote: > > M. David Peterson: > > > > > A recent inquiry on the Ruby.NET list brought up the question as to > > > whether or not the ability to reference ruby libs as embedded > > > resources is supported or will be supported via IronRuby. e.g., > > > > > > require ''res://assembly.dll/foo/bar'' > > > > Is the embedded resource a Ruby file or something else? > > What is the feature used for? > > I imagine the idea is to make deployment more robust by putting the > Ruby source somewhere that a user can''t screw up. ;) > > At least, that''s what *I''d* want it for...Right, but if you have a DLL already, you can just host IronRuby from C# and feed it Ruby code however you want to. I guess I''d be hesitant to change the meaning of "require". The way we have it now (require ''mscorlib'') is nice because it''s not changing the behavior. If you really wanted to you could write mscorlib.rb and run your code on another Ruby implementation. - John
M. David Peterson
2008-Feb-09 02:16 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
On Fri, 08 Feb 2008 19:09:25 -0700, John Messerly <jomes at microsoft.com> wrote:> Right, but if you have a DLL already, you can just host IronRuby from C# > and feed it Ruby code however you want to.True. So would that then be the prefered way to go about providing support?> I guess I''d be hesitant to change the meaning of "require". The way we > have it now (require ''mscorlib'') is nice because it''s not changing the > behavior. If you really wanted to you could write mscorlib.rb and run > your code on another Ruby implementation.Oh, I''m not suggesting changing the meaning, just adding a handler for the ''res'' protocol that would locate the source file via an assembly rather than the file system. To me, anyway, I don''t see any difference between what, require ''C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll'' ... means and what, require ''res://assemblyname.dll/foo/bar'' ... means, at least in regards to the fact that they both represent references to external libraries. -- /M:D M. David Peterson Co-Founder & Chief Architect, 3rd&Urban, LLC Email: m.david at 3rdandUrban.com | m.david at amp.fm Mobile: (206) 418-9027 http://3rdandUrban.com | http://amp.fm | http://www.oreillynet.com/pub/au/2354
Curt Hagenlocher
2008-Feb-09 02:54 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
On Feb 8, 2008 6:16 PM, M. David Peterson <m.david at xmlhacker.com> wrote:> On Fri, 08 Feb 2008 19:09:25 -0700, John Messerly <jomes at microsoft.com> > wrote: > > > I guess I''d be hesitant to change the meaning of "require". The way we > > have it now (require ''mscorlib'') is nice because it''s not changing the > > behavior. If you really wanted to you could write mscorlib.rb and run > > your code on another Ruby implementation. > > Oh, I''m not suggesting changing the meaning, just adding a handler for the > ''res'' protocol that would locate the source file via an assembly rather > than the file system. >After all, if urirequire can do this for "http:"... -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20080208/71d92fec/attachment.html
Michael Letterle
2008-Feb-09 03:11 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
I''d personally much rather see it done via something like urirequire (heck if it''s that needed, someone can write resrequire ;) ) Though there is a debate in there about if require should handle URIs in general or not, I think it''s one for Ruby in general to have... On Feb 8, 2008 9:54 PM, Curt Hagenlocher <curt at hagenlocher.org> wrote:> > On Feb 8, 2008 6:16 PM, M. David Peterson <m.david at xmlhacker.com> wrote: > > > > > On Fri, 08 Feb 2008 19:09:25 -0700, John Messerly <jomes at microsoft.com> > > wrote: > > > > > > > > > I guess I''d be hesitant to change the meaning of "require". The way we > > > have it now (require ''mscorlib'') is nice because it''s not changing the > > > behavior. If you really wanted to you could write mscorlib.rb and run > > > your code on another Ruby implementation. > > > > Oh, I''m not suggesting changing the meaning, just adding a handler for the > > ''res'' protocol that would locate the source file via an assembly rather > > than the file system. > > > After all, if urirequire can do this for "http:"... > > > -- > Curt Hagenlocher > curt at hagenlocher.org > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-- Michael Letterle [Polymath Programmer] http://michaeldotnet.blogspot.com
M. David Peterson
2008-Feb-09 03:35 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
On Fri, 08 Feb 2008 20:11:27 -0700, Michael Letterle <michael.letterle at gmail.com> wrote:> heck if it''s that needed, someone can write resrequireAssuming this would be seen as standard practice for implementing core language extensions, this would probably make the most sense, avoiding any compromise and ensuring that there''s a simple escape hatch to fallback to require if the resrequire method isn''t supported or if the requested embedded resource is unavailable. -- /M:D M. David Peterson Co-Founder & Chief Architect, 3rd&Urban, LLC Email: m.david at 3rdandUrban.com | m.david at amp.fm Mobile: (206) 418-9027 http://3rdandUrban.com | http://amp.fm | http://www.oreillynet.com/pub/au/2354
Michael Letterle
2008-Feb-09 03:57 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
My /personal/ view is that IronRuby should be Ruby first and .NET second. Anything that''s done outside of "normal" behaviour should be implemented outside of the core implementation. I''d almost go as far as to say that the current method of loading .NET assemblies is pushing it, but that''s an extreme view. So yes, if we''re doing something specific to this platform it should be implemented ontop of the core language not in it. It would be up to the person writing the code that uses resrequire (or urirequire) to perform the graceful fallback. On Feb 8, 2008 10:35 PM, M. David Peterson <m.david at xmlhacker.com> wrote:> On Fri, 08 Feb 2008 20:11:27 -0700, Michael Letterle > <michael.letterle at gmail.com> wrote: > > > heck if it''s that needed, someone can write resrequire > > Assuming this would be seen as standard practice for implementing core > language extensions, this would probably make the most sense, avoiding any > compromise and ensuring that there''s a simple escape hatch to fallback to > require if the resrequire method isn''t supported or if the requested > embedded resource is unavailable. > > -- > /M:D > > M. David Peterson > Co-Founder & Chief Architect, 3rd&Urban, LLC > Email: m.david at 3rdandUrban.com | m.david at amp.fm > Mobile: (206) 418-9027 > http://3rdandUrban.com | http://amp.fm | > http://www.oreillynet.com/pub/au/2354 > _______________________________________________ > > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-- Michael Letterle [Polymath Programmer] http://michaeldotnet.blogspot.com
M. David Peterson
2008-Feb-09 05:45 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
On Fri, 08 Feb 2008 20:57:58 -0700, Michael Letterle <michael.letterle at gmail.com> wrote:> So yes, if we''re doing something specific to this platform it should > be implemented ontop of the core language not in it. It would be up > to the person writing the code that uses resrequire (or urirequire) to > perform the graceful fallback.That makes complete sense and I can''t help but agree. :) -- /M:D M. David Peterson Co-Founder & Chief Architect, 3rd&Urban, LLC Email: m.david at 3rdandUrban.com | m.david at amp.fm Mobile: (206) 418-9027 http://3rdandUrban.com | http://amp.fm | http://www.oreillynet.com/pub/au/2354
Michael Letterle
2008-Feb-09 13:00 UTC
[Ironruby-core] Support For Referencing Ruby Libs As Embedded Resources?
For what it''s worth, this /is/ possible today: require ''mscorlib'' def resrequire(assembly, resource) assem = System::Reflection::Assembly.LoadFile assembly stream = assem.GetManifestResourceStream(resource) streamreader = System::IO::StreamReader.new stream filetext = streamreader.ReadToEnd file = File.new resource, ''w'' file.write filetext file.close require resource File.delete resource end I think I''d rather use eval then create a file, but we don''t have that yet ;) On Feb 9, 2008 12:45 AM, M. David Peterson <m.david at xmlhacker.com> wrote:> On Fri, 08 Feb 2008 20:57:58 -0700, Michael Letterle > <michael.letterle at gmail.com> wrote: > > > So yes, if we''re doing something specific to this platform it should > > be implemented ontop of the core language not in it. It would be up > > to the person writing the code that uses resrequire (or urirequire) to > > perform the graceful fallback. > > That makes complete sense and I can''t help but agree. :) > > -- > > /M:D > > M. David Peterson > Co-Founder & Chief Architect, 3rd&Urban, LLC > Email: m.david at 3rdandUrban.com | m.david at amp.fm > Mobile: (206) 418-9027 > http://3rdandUrban.com | http://amp.fm | > http://www.oreillynet.com/pub/au/2354 > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-- Michael Letterle [Polymath Programmer] http://michaeldotnet.blogspot.com