[#7055] More on VC++ 2005 — Austin Ziegler <halostatue@...>

Okay. I've got Ruby compiling. I'm attempting to get everything in

17 messages 2006/01/05
[#7058] Re: More on VC++ 2005 — nobuyoshi nakada <nobuyoshi.nakada@...> 2006/01/06

Hi,

[#7084] mathn: ugly warnings — hadmut@... (Hadmut Danisch)

Hi,

22 messages 2006/01/10
[#7097] Re: mathn: ugly warnings — Daniel Berger <Daniel.Berger@...> 2006/01/10

Hadmut Danisch wrote:

[#7098] Design contracts and refactoring (was Re: mathn: ugly warnings) — mathew <meta@...> 2006/01/10

Daniel Berger wrote:

[#7118] Re: Design contracts and refactoring (was Re: mathn: ugly warnings) — mathew <meta@...> 2006/01/12

*Dean Wampler *<deanwampler gmail.com> writes:

[#7226] Fwd: Re: Question about massive API changes — "Sean E. Russell" <ser@...>

Hello,

23 messages 2006/01/28
[#7228] Re: Question about massive API changes — Caleb Tennis <caleb@...> 2006/01/28

>

Re: Some troubles with an embedded ruby interpreter

From: wvdbos@...
Date: 2006-01-26 08:36:54 UTC
List: ruby-core #7215

Hi Matt,

I always load the file with the complete path, but the next should work
without it.

rb_load_file is a routine called from within rb_f_load (the routine called
by a Ruby-cript if you use 'load "afile.rb"')
But this routine is static, if you look at the source it calls rb_load:

So try calling rb_load (static VALUE rb_load(VALUE fileName,int wrap) )
should be something like:

VALUE f = rb_str_new2("cocoabug.rb");
rb_load(f,0);

Hope this helps
Wim van den Bos.


Matt Mower <matt.mower@gmail.com> wrote on 25/01/2006 22:13:21:

> Hi folks,
>
> I posted this message to ruby-talk yesterday but didn't receive any
> responses. I hope you don't mind if I repost it here since I hope it
> is more likely that people here have experience of embedding the ruby
> interpreter and likely things that might be done wrong in the attempt.
>
> I have embedded a Ruby 1.8.4 interpreter (compiled last night) into a
> Cocoa application built using the latest version of the XCode
> development tool on MacOSX. I embedded it by copying the
> libruby-static.a file into the XCode project and marking it to be
> included in the application bundle.
>
> Using the instructions in the 2nd edition of Programming Ruby I have
> managed to get the interpreter working and can execute Ruby statements
> using rb_eval_string(). In particular by using ruby_init_loadpath and
> rb_eval_string() to output $: I can be sure it is loaded the prepared
> ruby and not the system ruby.
>
> However I am having some problems when it comes to executing ruby
> scripts using rb_load_file with a script included in the App bundle. I
> don't think bundling is the issue since a bundle is just a directory
> as far as the underlying OS (and Ruby) are concerned.
>
> If I try to preload $: with the path to the Ruby scripts in my app bundle
>
>    NSBundle* mainBundle = [NSBundle mainBundle];
>    NSString* scriptPath = [mainBundle pathForResource:@"cocoabug"
> ofType:@"rb"];
>    NSString* scriptFolder = [scriptPath
stringByDeletingLastPathComponent];
>    NSString* operation = @"$: << \"";
>    operation = [operation stringByAppendingString:scriptFolder];
>    operation = [operation stringByAppendingString:@"\""];
>    rb_eval_string( [operation fileSystemRepresentation] );
>
> This code works and sets the $: correctly (as verified by printing it
> us rb_eval_string( "puts $:" );. However attempts to do:
>
>    rb_load_file( "cocoabug" )
> or
>    rb_load_file( "cocoabug.rb" )
>
> Both raise load errors.
>
>    [Session started at 2006-01-24 21:52:29 +0000.]
>    Load script: cocoabug.rb
>    From Folder:
/Users/matt/Projects/RiC/build/Debug/RiC.app/Contents/Resources
>    Ruby = 1.8.4
>    Path = /Users/matt/Projects/RiC/build/Debug/RiC.app/Contents/Resources
>    (eval): No such file or directory -- cocoabug.rb (LoadError)
>
>    RiC has exited with status -1.
>    [Session started at 2006-01-24 21:52:46 +0000.]
>    Load script: cocoabug
>    From Folder:
/Users/matt/Projects/RiC/build/Debug/RiC.app/Contents/Resources
>    Ruby = 1.8.4
>    Path = /Users/matt/Projects/RiC/build/Debug/RiC.app/Contents/Resources
>    (eval): No such file or directory -- cocoabug (LoadError)
>
> However attempting the same thing from IRB using:
>
>    $:.clear
>    $: <<
"/Users/matt/Projects/RiC/build/Debug/RiC.app/Contents/Resources"
>    require "cocoabug"
>
> Works fine.
>
> The alternative approach that I tried was to load the file using the
> complete path, i.e.
>
>    rb_load_file( [scriptPath fileSystemRepresentation] );
>
> Does not raise a LoadError, but doesn't appear to work either.
> Whatever I put in cocoabug.rb does not get executed including raising
> Exception.new which should (taking the discussion of rb_protect into
> account) have terminated the whole process.
>
> I'm kinda stumped as to what's wrong but I'm so new to Cocoa/XCode and
> the inner workings of the Ruby interpreter that I'm not sure where to
> look next for the problem.
>
> The source code to my app is available from:
>    http://matt.blogs.it/share/source/main.txt
>
> If anyone could help me out I'd be much obliged.
>
> Regards,
>
> Matt
>
> --
> Matt Mower :: http://matt.blogs.it/
>

--------------------------------------------------------------------------------------------

Disclaimer

De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is
uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht
ontvangt, wordt u verzocht de inhoud niet te gebruiken en de afzender
direct te informeren door het bericht te retourneren. De afzender sluit
iedere aansprakelijkheid uit die voortvloeit uit elektronische verzending.

In This Thread