Hi, Im working on Ruby C extension, FOllowing is the code of my myRuby.c
file containing implementation of some function which are accessed from
ruby script.
myRuby.c:
static VALUE myMethod(VALUE self, VALUE exc)
{
int a = TYPE(exc);
printf(" %d ", a );
// Some manipulation on exc i.e. Access its attributes
}
void Init_myRuby()
{
VALUE mRuby = rb_define_module(“myRuby”);
VALUE mException = rb_define_class_under(mRuby, “Exception”,
rb_eRuntimeError);
rb_define_singleton_method(mRuby, “myMethod”, myMethod, 4);
}
AND following id the code from client.rb which invokes the function from
above myRuby.c file.
client.rb:
require ‘myRuby’
def raiseExc()
exception = myRuby::Exception.new(“status”,“lasterror”,“function()”,
“Calling some”)
myRuby::myMethod(exception, “Exception message: %s, Exception object
%d”, “Hi from Exception”, 100)
end
raiseExc()