[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Extend Ruby with c error

liubin

6/29/2005 1:11:00 AM

***
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: ???????????????????? - 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);

*/
}




3 Answers

Nakada, Nobuyoshi

6/29/2005 1:48:00 AM

0

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?

--
Nobu Nakada


liubin

6/29/2005 2:00:00 AM

0

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" <nobuyoshi.nakada@ge.com>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
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?
>
> --
> Nobu Nakada



Nakada, Nobuyoshi

6/29/2005 4:24:00 AM

0

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.

--
Nobu Nakada