Extend Ruby with c error

L

liubin

***
simple programm copy from programming ruby.
write a ruby file :
require "Test"
#t = Test.new
#t.add("Bill Chase")

when run this file ,get error:

127: $B;XDj$5$l$?%W%m%7!<%8%c$,8+$D$+$j$^$;$s!#(B - Init_Test
c:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt/Test.dll
c:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt/Test.dll
Press ENTER to close the window...

anyone has some ideas for this problem ? thanks

***
os win2000 pro japanese version + sp4
vc++6.0
ruby1.8

***
source code of Test.dll:
#include "ruby.h"

static VALUE t_init(VALUE self)
{
VALUE arr;

arr = rb_ary_new();
rb_iv_set(self, "@arr", arr);
return self;
}


static VALUE t_add(VALUE self, VALUE anObject)
{
VALUE arr;


arr = rb_iv_get(self, "@arr");
rb_ary_push(arr, anObject);
return arr;
}


VALUE cTest;


void Init_Test() {
cTest = rb_define_class("Test", rb_cObject);
rb_define_method(cTest, "initialize", RUBY_METHOD_FUNC(t_init), 0);
rb_define_method(cTest, "add", RUBY_METHOD_FUNC(t_add), 1);
/**
RUBY_METHOD_FUNC helps.

like this:
rb_define_method(cTest, "add", RUBY_METHOD_FUNC(t_add), 1);

*/
}
 
N

nobuyoshi nakada

Hi,

At Wed, 29 Jun 2005 10:11:10 +0900,
liubin wrote in [ruby-talk:146723]:
source code of Test.dll:

What's the name of this file? Maybe, .cpp file?
 
L

liubin

sorry,the source is a .cpp file
and i change to a .c file with the change delete
RUBY_METHOD_FUNC() ,i can build a dll file ,but when use in .rb file the
error still occurs.
----- Original Message -----
From: "nobuyoshi nakada" <[email protected]>
To: "ruby-talk ML" <[email protected]>
Sent: Wednesday, June 29, 2005 9:48 AM
Subject: Re: Extend Ruby with c error

Hi,

At Wed, 29 Jun 2005 10:11:10 +0900,
liubin wrote in [ruby-talk:146723]:
source code of Test.dll:

What's the name of this file? Maybe, .cpp file?
 
N

nobuyoshi nakada

Hi,

At Wed, 29 Jun 2005 11:00:17 +0900,
liubin wrote in [ruby-talk:146729]:
sorry,the source is a .cpp file
and i change to a .c file with the change delete
RUBY_METHOD_FUNC() ,i can build a dll file ,but when use in .rb file the
error still occurs.

Your code worked fine without any changes on my box.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top