Embedding Ruby (again)

Hi,
Here I go again with some (idiotic) embedding questions (yeah, I’ve read

README.EXT and I’ve scanned through the mailing list for similar
topics). First of all, I’m getting pretty cool with extending Ruby with

C (not by using SWIG, but by doing all by hand). Now, say I’ve written
some C code which extends Ruby with class Test. Now, say I embedd Ruby
in my app. Would I be able to create some objects in Ruby (the embedded

one) of type Test? How can that be done? For example, in order to create

an array, you would write something like:
VALUE array = rb_ary_new();
Now, how can I do that for the class I’ve just exported into Ruby?
Hope I made myself clear.
Regards,
Radu

P.S. Now, this might be really IDIOTIC, but why do I get “undefined
reference” errors when I try to links against libruby? I’m using gcc
2.95.3 and glibc 2.2.1. I’m using something like gcc -o test
-I/usr/lib/i386-linux -L/usr/lib/i386-linux -lruby main.c

This e-mail was scanned by RAV AntiVirus!

···

Xnet scaneaza automat toate mesajele impotriva virusilor folosind RAV AntiVirus.
Xnet automatically scans all messages for viruses using RAV AntiVirus.

Nota: RAV AntiVirus poate sa nu detecteze toti virusii noi sau toate variantele lor. Va rugam sa luati in considerare ca exista un risc de fiecare data cand deschideti fisiere atasate si ca MobiFon nu este responsabila pentru nici un prejudiciu cauzat de virusi.
Disclaimer: RAV AntiVirus may not be able to detect all new viruses and variants. Please be aware that there is a risk involved whenever opening e-mail attachments to your computer and that MobiFon is not responsible for any damages caused by viruses.

one) of type Test? How can that be done? For example, in order to create

an array, you would write something like:
VALUE array = rb_ary_new();
Now, how can I do that for the class I've just exported into Ruby?

Well, in ruby you just write (if your class is in test.rb)

    require "test"
    a = Test.new

now in C this give

    rb_require("test");
    tt_cTest = rb_const_get(rb_cObject, rb_intern("Test"));
    a = rb_funcall2(tt_cTest, rb_intern("new"), 0, 0);

P.S. Now, this might be really IDIOTIC, but why do I get "undefined
reference" errors when I try to links against libruby? I'm using gcc
2.95.3 and glibc 2.2.1. I'm using something like gcc -o test
-I/usr/lib/i386-linux -L/usr/lib/i386-linux -lruby main.c

Look at [ruby-talk:36676] to find the flags

http://www.ruby-talk.org/36676

Guy Decoux