From: Dreamcat Four on
Joel VanderWerf wrote:
> Dreamcat Four wrote:
>> http://gist.github.com/471434
> Is it possible to simplify the example a bit? I can't tell where the

Here is the example2.rb, but modified to reproduce this scenario.

http://github.com/dreamcat4/script/commit/0a89728d

When we run the same ruby code directly (example2-no-wrapper.rb), there
is no error. So the script wrapper is doing something differently than
ruby would normally.

My question:
Can find a way to get around this without touching the loaded source
code?

> missing const is actually defined.
>
>> I noticed that there is a redefinition of require in script.rb. Is that
>> method meant to be handling that?
>>
>> http://redshift.sourceforge.net/script/doc/classes/Script.html#M000003
>
> There's an example of using require with script in examples/program2.rb.
> Maybe that helps?
>
> Sorry not to be more helpful...

--
Posted via http://www.ruby-forum.com/.

From: Joel VanderWerf on
On Sun, Jul 11, 2010 at 3:07 AM, Dreamcat Four <dreamcat4(a)gmail.com> wrote:
> Joel VanderWerf wrote:
>> However, you don't get easy access to the anonymous module. If you want
>> that, I have a little library that may be helpful:
>>
>> http://redshift.sourceforge.net/script/
>
> This is great, but seems to blows up when requiring other files
>
> http://github.com/dreamcat4/plist4r/blob/master/lib/plist4r/backend/c_f_property_list.rb#L8
>
> http://gist.github.com/471434
>
> I noticed that there is a redefinition of require in script.rb. Is that
> method meant to be handling that?
>
> http://redshift.sourceforge.net/script/doc/classes/Script.html#M000003

Yes. The problem is in the way your script references the other files.
You've got absolute paths (which makes sense in the no-wrapper case),
but the Script class is expecting relative. The problem goes away
(AFAICT) with this patch:

--- /home/vjoel/tmp/dc2/examples/scripts/script.rb 2010-07-13
17:13:47.673562875 -0700
+++ - 2010-07-13 17:15:18.375246675 -0700
@@ -1,6 +1,6 @@
puts "in #{__FILE__}, line #{__LINE__}"

-load File.dirname(__FILE__)+"/sub-script.rb"
+load "sub-script.rb"

OUTPUT = ["input was #{INPUT}"]

@@ -9,10 +9,10 @@
end
end

-require File.dirname(__FILE__)+'/lib/a-class'
+require 'lib/a-class'

-require File.dirname(__FILE__)+'/lib/x-accessor'
-require File.dirname(__FILE__)+'/lib/x-accessor' # only loaded once
+require 'lib/x-accessor'
+require 'lib/x-accessor' # only loaded once

# Falls back to Kernel.load, since "benchmark.rb" isn't in the current dir.
load "benchmark.rb" unless $LOADED_FEATURES.include?("benchmark.rb")

From: Dreamcat Four on

Here is a fix to the require() and load() methods. Its easier to patch
it there and just not to assume those methods are being given relative
paths.

http://github.com/dreamcat4/script/commit/e7d585b5

Joel VanderWerf wrote:
> On Sun, Jul 11, 2010 at 3:07 AM, Dreamcat Four <dreamcat4(a)gmail.com>
> wrote:
>> http://gist.github.com/471434
>>
>> I noticed that there is a redefinition of require in script.rb. Is that
>> method meant to be handling that?
>>
>> http://redshift.sourceforge.net/script/doc/classes/Script.html#M000003
>
> Yes. The problem is in the way your script references the other files.
> You've got absolute paths (which makes sense in the no-wrapper case),
> but the Script class is expecting relative. The problem goes away
> (AFAICT) with this patch:
>
> --- /home/vjoel/tmp/dc2/examples/scripts/script.rb 2010-07-13
> 17:13:47.673562875 -0700
> +++ - 2010-07-13 17:15:18.375246675 -0700
> @@ -1,6 +1,6 @@
> puts "in #{__FILE__}, line #{__LINE__}"
>
> -load File.dirname(__FILE__)+"/sub-script.rb"
> +load "sub-script.rb"
>
> OUTPUT = ["input was #{INPUT}"]
>
> @@ -9,10 +9,10 @@
> end
> end
>
> -require File.dirname(__FILE__)+'/lib/a-class'
> +require 'lib/a-class'
>
> -require File.dirname(__FILE__)+'/lib/x-accessor'
> -require File.dirname(__FILE__)+'/lib/x-accessor' # only loaded once
> +require 'lib/x-accessor'
> +require 'lib/x-accessor' # only loaded once
>
> # Falls back to Kernel.load, since "benchmark.rb" isn't in the current
> dir.
> load "benchmark.rb" unless $LOADED_FEATURES.include?("benchmark.rb")

--
Posted via http://www.ruby-forum.com/.

From: Dreamcat Four on
Dreamcat Four wrote:
>
> Here is a fix to the require() and load() methods. Its easier to patch
> it there and just not to assume those methods are being given relative
> paths.
>
> http://github.com/dreamcat4/script/commit/e7d585b5

--- a/lib/script.rb
+++ b/lib/script.rb
@@ -52,7 +52,11 @@ class Script < Module
# from those sub files.

def load(file, wrap = false)
- load_in_module(File.join(@__dir, file))
+ if file =~ /^\//
+ load_in_module(file)
+ else
+ load_in_module(File.join(@__dir, file))
+ end
true
rescue MissingFile
super
@@ -70,7 +74,11 @@ class Script < Module
def require(feature)
unless @__loaded_features[feature]
@__loaded_features[feature] = true
- file = File.join(@__dir, feature)
+ if feature =~ /^\//
+ file = feature
+ else
+ file = File.join(@__dir, feature)
+ end
file += ".rb" unless /\.rb$/ =~ file
load_in_module(file)
end
--
1.6.6.1


>
> Joel VanderWerf wrote:
>> On Sun, Jul 11, 2010 at 3:07 AM, Dreamcat Four <dreamcat4(a)gmail.com>
>> wrote:
>>> http://gist.github.com/471434
>>>
>>> I noticed that there is a redefinition of require in script.rb. Is that
>>> method meant to be handling that?
>>>
>>> http://redshift.sourceforge.net/script/doc/classes/Script.html#M000003
>>
>> Yes. The problem is in the way your script references the other files.
>> You've got absolute paths (which makes sense in the no-wrapper case),
>> but the Script class is expecting relative. The problem goes away
>> (AFAICT) with this patch:
>>
>> --- /home/vjoel/tmp/dc2/examples/scripts/script.rb 2010-07-13
>> 17:13:47.673562875 -0700
>> +++ - 2010-07-13 17:15:18.375246675 -0700
>> @@ -1,6 +1,6 @@
>> puts "in #{__FILE__}, line #{__LINE__}"
>>
>> -load File.dirname(__FILE__)+"/sub-script.rb"
>> +load "sub-script.rb"
>>
>> OUTPUT = ["input was #{INPUT}"]
>>
>> @@ -9,10 +9,10 @@
>> end
>> end
>>
>> -require File.dirname(__FILE__)+'/lib/a-class'
>> +require 'lib/a-class'
>>
>> -require File.dirname(__FILE__)+'/lib/x-accessor'
>> -require File.dirname(__FILE__)+'/lib/x-accessor' # only loaded once
>> +require 'lib/x-accessor'
>> +require 'lib/x-accessor' # only loaded once
>>
>> # Falls back to Kernel.load, since "benchmark.rb" isn't in the current
>> dir.
>> load "benchmark.rb" unless $LOADED_FEATURES.include?("benchmark.rb")

--
Posted via http://www.ruby-forum.com/.

From: Joel VanderWerf on
Dreamcat Four wrote:
> Here is a fix to the require() and load() methods. Its easier to patch
> it there and just not to assume those methods are being given relative
> paths.

Sure, that makes sense. I'll merge that in the next release. Thanks!