From: Joshua Ballanco Date: 2012-08-03T19:21:48+09:00 Subject: [ruby-core:46958] Re: (Half-baked DRAFT) new `require' framework --501ba632_66a48d11_668d Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Tuesday, July 31, 2012 at 3:29 PM, SASADA Koichi wrote: > Now, `require' only loads `.rb' script or `.so' files from `file system'. > > (Proposal-1) > This proposal extends the current limitation of require: > > (1) load script which is represented by other than `.rb' and `.so'. > (example: pre-compiled file, encrypted file) > > (2) load script from location from other than `file system'. > (example: require from zip archive, require over network, > require files provided by gem efficiently using file location db) > > I'll echo what Charles said in his response: file lookup and code loading should be handled independently. I would even go so far as to say that code loading could be made an independent API from require, enabling the loading of code from memory or, say, from a network socket. > == Related work > > === JRuby > > JRuby can require file from `.jar' (and .war file? sorry i'm not sure). > JRuby also extends file path like VFS (virtual file system). JRuby can > open a file in a .jar file like file system. > (JRuby GURU: Please complement this section!) > > === Rubinius > > Rubinius supports AOT compile (a ruby script to a compiled file). > (Rubinius GURU: Please complement it!) > > === MacRuby MacRuby has modified require to be able to load compiled and linked object files (*.rbo) like so: Earth: ~/Desktop > echo "def foo; puts 'foo from file a.rb'; end" > a.rb Earth: ~/Desktop > echo "require 'a'; foo" > b.rb Earth: ~/Desktop > macrubyc -C a.rb Earth: ~/Desktop > macrubyc -C b.rb Earth: ~/Desktop > rm a.rb b.rb Earth: ~/Desktop > macruby -e "require './b'" foo from file a.rb But, beyond that, MacRuby can also "require" a file in a compiled, linked, dynamic library: Earth: ~/Desktop > echo "def foo; puts 'foo from file a.rb'; end" > a.rb Earth: ~/Desktop > echo "require 'a'; foo" > b.rb Earth: ~/Desktop > macrubyc a.rb b.rb -o ab.dylib --dylib Earth: ~/Desktop > rm a.* b.* Earth: ~/Desktop > echo "require 'b'" > c.rb Earth: ~/Desktop > macrubyc c.rb ab.dylib -o awesome Earth: ~/Desktop > ./awesome foo from file a.rb Right now, we accomplish this with a variety of "tricks" (i.e. features of OS X's dynamic loader), but it would be nice to have a more formalized API for doing the same thing. --501ba632_66a48d11_668d Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
On Tuesday, July 31, = 2012 at 3:29 PM, SASADA Koichi wrote:
Now, =60re= quire' only loads =60.rb' script or =60.so' files from =60file system'.

(Proposal-1)
This proposal ex= tends the current limitation of require:

(1) l= oad script which is represented by other than =60.rb' and =60.so'.
<= div> (example: pre-compiled file, encrypted file)

=
(2) load script from location from other than =60file system'.
(example: require from zip archive, require over network,
require files provided by gem efficiently using file location = db)

I'll echo wh= at Charles said in his response: file lookup and code loading should be h= andled independently. I would even go so far as to say that code loading = could be made an independent API from require, enabling the loading of co= de from memory or, say, from a network socket. 

=
=3D=3D Related work<= div>

=3D=3D=3D JRuby

JRu= by can require file from =60.jar' (and .war file=3F sorry i'm not sure).<= /div>
JRuby also extends file path like V=46S (virtual file system).= JRuby can
open a file in a .jar file like file system.
<= div>(JRuby GURU: Please complement this section=21)

<= div>=3D=3D=3D Rubinius

Rubinius supports AOT com= pile (a ruby script to a compiled file).
(Rubinius GURU: Please= complement it=21)

=3D=3D=3D MacRuby

MacRuby has modified requir= e to be able to load compiled and linked object files (*.rbo) like so:

Earth: =7E/Desktop > echo =22def foo; puts 'foo= from file a.rb'; end=22 > a.rb
Earth: =7E/Desktop > echo= =22require 'a'; foo=22 > b.rb
Earth: =7E/Desktop > macru= byc -C a.rb
Earth: =7E/Desktop > macrubyc -C b.rb
= Earth: =7E/Desktop > rm a.rb b.rb
Earth: =7E/Desktop > ma= cruby -e =22require './b'=22
foo from file a.rb

<= /div>
But, beyond that, MacRuby can also =22require=22 a file in a co= mpiled, linked, dynamic library:

Earth: =7E= /Desktop > echo =22def foo; puts 'foo from file a.rb'; end=22 > a.r= b
Earth: =7E/Desktop > echo =22require 'a'; foo=22= > b.rb                  =     
Earth: =7E/Desktop > macruby= c a.rb b.rb -o ab.dylib --dylib
Earth: =7E/Desktop &= gt; rm a.* b.*
Earth: =7E/Desktop > echo =22requi= re 'b'=22 > c.rb
Earth: =7E/Desktop > macrubyc= c.rb ab.dylib -o awesome
Earth: =7E/Desktop > ./= awesome
foo from file a.rb

Right= now, we accomplish this with a variety of =22tricks=22 (i.e. features of= OS X's dynamic loader), but it would be nice to have a more formalized A= PI for doing the same thing.
 
--501ba632_66a48d11_668d--