Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > embedding, 'require' and extensions

Reply
Thread Tools

embedding, 'require' and extensions

 
 
Phil Tomson
Guest
Posts: n/a
 
      10-29-2004
I've basically taken the embedding example from pickaxeII and the only
thing I've added is for the Ruby program to do a 'require' of a file known
to exist in the library.

Here is the relevant part of the C-side code:
//summer.c
int main(void) {
int value;
int* next = Values;

ruby_init();
ruby_init_loadpath();
ruby_script("embedded");
rb_require("sum.rb"); //ruby script is sum.rb

ruby_finalize();
exit(0);
}
//end of summer.c

So the ruby_init_loadpath() should be setting up the loadpath correctly,
and I can confirm this by making the ruby script to be required (sum.rb)
like so:

#sum.rb
puts $:

Now if I run summer, I get:
$ ./summer
/usr/local/lib/ruby/site_ruby/1.8
/usr/local/lib/ruby/site_ruby/1.8/i686-linux
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/1.8
/usr/local/lib/ruby/1.8/i686-linux
 
Reply With Quote
 
 
 
 
ts
Guest
Posts: n/a
 
      10-30-2004
>>>>> "P" == Phil Tomson <(E-Mail Removed)> writes:

P> Here is the relevant part of the C-side code:

You don't give the most important part : how do you build your
executable ?

You must use the value given in rbconfig.rb to build the command line, in
your case you've probably forgotten -rdynamic when you have compiled your
source.

Another thing

P> rb_require("sum.rb"); //ruby script is sum.rb

You *must* protect any call to a ruby function which can generate an
error, with rb_protect(), otherwise ruby will crash




Guy Decoux






 
Reply With Quote
 
 
 
 
Phil Tomson
Guest
Posts: n/a
 
      10-30-2004
In article <(E-Mail Removed)>,
ts <(E-Mail Removed)> wrote:
>>>>>> "P" == Phil Tomson <(E-Mail Removed)> writes:

>
>P> Here is the relevant part of the C-side code:
>
> You don't give the most important part : how do you build your
> executable ?
>
> You must use the value given in rbconfig.rb to build the command line, in
> your case you've probably forgotten -rdynamic when you have compiled your
> source.


Here's how I built:
$ gcc -I/usr/local/lib/ruby/1.8/i686-linux -g -c -o summer.o summer.c
$ gcc -o summer summer.o -L/usr/local/lib/ruby/1.8/i686-linux -lruby-static -ldl -lm -lcrypt
-rdynamic

It didn't make any difference if I used rdynamic or not.

>
> Another thing
>
>P> rb_require("sum.rb"); //ruby script is sum.rb
>
> You *must* protect any call to a ruby function which can generate an
> error, with rb_protect(), otherwise ruby will crash
>


Yes, I know. I was only doing a quick/small test before adding more.

Phil
 
Reply With Quote
 
ts
Guest
Posts: n/a
 
      10-31-2004
>>>>> "P" == Phil Tomson <(E-Mail Removed)> writes:

P> $ gcc -I/usr/local/lib/ruby/1.8/i686-linux -g -c -o summer.o summer.c
P> $ gcc -o summer summer.o -L/usr/local/lib/ruby/1.8/i686-linux -lruby-static -ldl -lm -lcrypt
P> -rdynamic

P> It didn't make any difference if I used rdynamic or not.

Well, at moulon


svg% cat aa.c
#include <ruby.h>

static VALUE
tt()
{
return rb_require("sum.rb");
}

int main()
{
int value;

ruby_init();
ruby_init_loadpath();
ruby_script("embedded");
rb_protect(tt, Qnil, &value);
if (value) {
VALUE err = rb_inspect(rb_gv_get("$!"));
fprintf(stderr, "ERR %s\n", StringValuePtr(err));
}

ruby_finalize();
exit(0);
}
svg%

svg% cc -I. -I/usr/local/lib/ruby/1.8/i686-linux aa.c -L/usr/local/lib -lruby-static -ldl -lcrypt -lm
svg%

svg% ./a.out
ERR #<LoadError: /usr/local/lib/ruby/1.8/i686-linux/openssl.so: undefined symbol: rb_eRuntimeError - /usr/local/lib/ruby/1.8/i686-linux/openssl.so>
svg%

svg% cc -I. -I/usr/local/lib/ruby/1.8/i686-linux aa.c -L/usr/local/lib -lruby-static -ldl -lcrypt -lm -rdynamic
svg%

svg% ./a.out
svg%




Guy Decoux


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox 2 and broken extensions and themes GraB NZ Computing 1 12-03-2006 05:57 PM
Unable to access extensions menu or add extensions (I've tried past suggestions) nospam@spam.com Firefox 8 12-01-2005 01:33 AM
Error after updating Firefox themes and extensions Christine Marie Firefox 1 10-25-2004 11:07 PM
Really get sick and tired of this. Themes and extensions DON'T install??!!! Galaxy Firefox 8 07-03-2004 11:55 PM
Mozilla, Quicktime, and file extensions Matt O'Toole Firefox 0 12-07-2003 08:47 PM



Advertisments