From: wvdbos@... Date: 2006-01-26T17:36:54+09:00 Subject: Re: Some troubles with an embedded ruby interpreter --0__=4EBBFB91DFBEE4F58f9e8a93df938690918c4EBBFB91DFBEE4F5 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: quoted-printable 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 calle= d 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 =3D rb_str_new2("cocoabug.rb"); rb_load(f,0); Hope this helps Wim van den Bos. Matt Mower 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 bund= le > > NSBundle* mainBundle =3D [NSBundle mainBundle]; > NSString* scriptPath =3D [mainBundle pathForResource:@"cocoabug" > ofType:@"rb"]; > NSString* scriptFolder =3D [scriptPath stringByDeletingLastPathComponent]; > NSString* operation =3D @"$: << \""; > operation =3D [operation stringByAppendingString:scriptFolder]; > operation =3D [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 =3D 1.8.4 > Path =3D /Users/matt/Projects/RiC/build/Debug/RiC.app/Contents/Resou= rces > (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 =3D 1.8.4 > Path =3D /Users/matt/Projects/RiC/build/Debug/RiC.app/Contents/Resou= rces > (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. --0__=4EBBFB91DFBEE4F58f9e8a93df938690918c4EBBFB91DFBEE4F5--