Ah-ha! (or, Doh!) I had defined my ‘get’ methods with the wrong
signature.
I had set them up as if they were rb_define_method(…, -1) methods
taking (argc, argv, self) instead of (self)
Your test example made me realize the error of my ways.
Thanks!!
Patrick Bennett
···
-----Original Message-----
From: ts [mailto:decoux@moulon.inra.fr]
Sent: Thursday, November 13, 2003 11:41 AM
To: ruby-talk ML
Cc: ruby-talk@ruby-lang.org
Subject: Re: Problem with exception class and instance vars
What am I doing wrong?
Difficult to say : probably ruby don’t like C++ :-))
svg% cat aa.c
#include <ruby.h>
static VALUE evx;
static VALUE
aa_tt(obj)
VALUE obj;
{
VALUE thr = rb_exc_new2(evx, “”);
rb_iv_set(thr, “@event”, rb_str_new2(“”));
rb_iv_set(thr, “@msg”, rb_str_new2(“”));
rb_exc_raise(thr);
}
static VALUE
aa_event(obj)
VALUE obj;
{
return rb_iv_get(obj, “@event”);
}
static VALUE
aa_msg(obj)
VALUE obj;
{
return rb_iv_get(obj, “@msg”);
}
void Init_aa()
{
evx = rb_define_class(“EventException”, rb_eStandardError);
rb_define_method(evx, “event”, aa_event, 0);
rb_define_method(evx, “msg”, aa_msg, 0);
rb_define_global_function(“tt”, aa_tt, 0);
}
svg%
svg% cat b.rb
#!/usr/bin/ruby
require ‘aa’
begin
tt
rescue EventException => ex
puts “Event : #{ex.event} Msg : #{ex.msg} Exception : #{ex}” end
svg%
svg% b.rb
Event : Msg : Exception : svg%
Guy Decoux