>>>>> "B" == Bennett, Patrick <Patrick.Bennett@inin.com> writes:
B> 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, "<exception>");
rb_iv_set(thr, "@event", rb_str_new2("<string>"));
rb_iv_set(thr, "@msg", rb_str_new2("<another string>"));
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 : <string> Msg : <another string> Exception : <exception>
svg%
Guy Decoux