c 中 ruby Exception 类对象的扩展是什么?
您好,我在 c 中有以下代码,它是从 ruby 脚本调用的,
static VALUE myMethod(VALUE self, VALUE exc)
{
int a = TYPE(exc);
printf(" %d ", a );
// Some process on exc
}
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);
}
以下是 ruby 客户端脚本的代码,
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()
我从 ruby 客户端调用 myMethod() 函数。谁能告诉我如何访问c文件中的异常类对象“exc”及其所有属性。
HI i have following code in c which is invoked from a ruby script,
static VALUE myMethod(VALUE self, VALUE exc)
{
int a = TYPE(exc);
printf(" %d ", a );
// Some process on exc
}
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);
}
Following is the code of ruby client script,
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()
I invoke myMethod() function from ruby client. Can any one tell me how to access Exception class object "exc" in c file and its all attributes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
rb_funcall
调用exc
对象上的方法。假设 exc 有一个
#description
方法:如果您需要指定参数:
Use
rb_funcall
to call methods on yourexc
object.Assuming the exc had a
#description
method:Of if you need to specify arguments: