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);
*/
}