< :the previous in number
^ :the list in numerical order
> :the next in number
P :the previous (in thread)
N :the next (in thread)
|<:the top of this thread
>|:the next thread
^ :the parent (reply-to)
_:the child (an article replying to this)
>:the elder article having the same parent
<:the youger article having the same parent
---:split window and show thread lists
| :split window (vertically) and show thread lists
~ :close the thread frame
.:the index
..:the index of indices
>>>>> "R" == Rasputin <rasputin / shrike.mine.nu> writes:
R> rasputin@shrike cruby$ gcc -c -o Test.o -I \
R> /usr/local/lib/ruby/1.6/i386-freebsd4/ simple.c
Well, the example is
svg% cat Test.c
#include <ruby.h>
static VALUE
t_init(VALUE self)
{
rb_iv_set(self, "@arr", rb_ary_new());
return self;
}
static VALUE
t_add(VALUE self, VALUE anObject)
{
VALUE arr = rb_iv_get(self, "@arr");
rb_ary_push(arr, anObject);
return arr;
}
void Init_Test()
{
VALUE cTest = rb_define_class("Test", rb_cObject);
rb_define_method(cTest, "initialize", t_init, 0);
rb_define_method(cTest, "add", t_add, 1);
}
svg%
The best after is to create a file extconf.rb
svg% cat extconf.rb
#!/usr/bin/ruby
require 'mkmf'
create_makefile('Test')
svg%
Then
svg% ruby extconf.rb
creating Makefile
svg%
svg% make
gcc -fPIC -g -O2 -I. -I/usr/local/lib/ruby/1.8/i686-linux -I/usr/local/lib/ruby/1.8/i686-linux -I. -c Test.c
gcc -shared -rdynamic -L"/usr/local/lib" -o Test.so Test.o -ldl -lcrypt -lm -lc
svg%
and finally you can use it :
svg% ruby -rTest -e 't = Test.new; t.add("Bill Chase"); p t'
#<Test:0x4009a0f0 @arr=["Bill Chase"]>
svg%
It's important that the name of the extension ('Test') is the same than
the name of the init function ('Init_Test')
Guy Decoux