[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Problems loading scripts using embedded Ruby interpreter

Matt Mower

1/25/2006 12:09:00 AM

Hi folks,

I am trying to embed the Ruby interpreter into a Cocoa application and
am having some problems. I hope I can find some help here.

My aim is to embed a specific Ruby interpreter into the Cocoa
application (i.e. the ruby interpreter & any necessary files should be
in the app bundle) and execute a script from within the bundle.

In XCode 2.2. (latest version) I have created a Cocoa application.
Then from a fresh ruby-1.8.4 i have copied the libruby-static.a into
the Resources folder of my project and told XCode to copy it to the
app.

Next I started modifying main.m adding:

ruby_init();
ruby_script( "CocoaBug" );
ruby_eval_string( "puts \"Path = #{$:}\"" );
// rb_load_file( fileName );
ruby_finalize();

However, although the Ruby interpreter seems to work fine, all is not
well. The application correctly prints the contents of $: but I
cannot get it to load the file through rb_load_file.

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. 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 terminate 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...share/sourc...

If anyone could help me out I'd be much obliged.

Regards,

Matt

--
Matt Mower :: http://matt...


4 Answers

The Peeler

6/28/2013 7:51:00 PM

0

On Fri, 28 Jun 2013 11:48:07 -0700, my personal traumatized little idiot,
now posting as FAKE Malcolm "Mal" Reynolds, wrote:

>>>> Yeah, he's a LOT like you, my traumatized punching bag! LOL
>>>
>>> He, IS Grik anus!
>>
>> Well, write him an email, sick little idiot! LOL
>
> Oh, shut the fuck up finally, you pathetic fool!

Truth hurts, eh, poor autistic twerp! LOL

The Peeler

6/29/2013 2:54:00 PM

0

On Fri, 28 Jun 2013 11:48:07 -0700, "Malcom \"Mal\" Reynolds"
<atlas-bugged@invalid.invalid> wrote:

>In article <eSizt.54097$B82.52806@newsfe07.iad>,
> The Peeler <finishingoff@themoronicRevd.invalid> wrote:
>
>> On Fri, 28 Jun 2013 06:18:33 -0700, The Rectum, the resident psychopath of
>> sci and scj, FAKING his time zone again and IMPERSONATING his master, The
>> Peeler, wrote:
>>
>> >> >>
>> >> >> STILL traumatized, poor traumatized fool? LMAO!
>> >> >
>> >> > STILL???? LMAO1
>> >>
>> >> Yeah, he's a LOT like you, my traumatized punching bag! LOL
>> >
>> > He, IS Grik anus!
>>
>> Well, write him an email, sick little idiot! LOL
>
>Oh, shut the fuck up finally, you pathetic fool!

Oh make, me innit anus! <tsk>

The Peeler

6/29/2013 4:18:00 PM

0

On Sat, 29 Jun 2013 07:53:54 -0700, The Rectum, the resident psychopath of
sci and scj, FAKING his time zone again and IMPERSONATING his master, The
Peeler, wrote:


>>> Well, write him an email, sick little idiot! LOL
>>
>>Oh, shut the fuck up finally, you pathetic fool!
>
> Oh make, me innit anus! <tsk>

He'd have to stitch up your anus first to make YOU shut up, eh, The Rectum?
LOL

--
Retarded, anal, subnormal and extremely proud of it: our resident
psychopath, The Retard (aka "The Rectum").

The Peeler

6/29/2013 4:56:00 PM

0

On Fri, 28 Jun 2013 21:51:03 +0200, The Peeler
<finishingoff@themoronicRevd.invalid> wrote:

>On Fri, 28 Jun 2013 11:48:07 -0700, my personal traumatized little idiot,
>now posting as FAKE Malcolm "Mal" Reynolds, wrote:
>
>>>>> Yeah, he's a LOT like you, my traumatized punching bag! LOL
>>>>
>>>> He, IS Grik anus!
>>>
>>> Well, write him an email, sick little idiot! LOL
>>
>> Oh, shut the fuck up finally, you pathetic fool!
>
>Truth hurts me, eh, I'm just a poor autistic Grik twerp! LOL

You, ARE The Grik anus! LOL