1

也许更一般地说,你如何将一个用 C 编写的块传递给另一个接受块的 C 函数?我知道我可以做这样的事情:

VALUE refine_foobar(VALUE block_arg, VALUE data, int argc, VALUE* argv) {
  // block code here
  return Qnil;
}

void Init_mything() {
  VALUE mod = rb_define_module("Foobar");
  rb_block_call(mod, rb_intern("refine"), 0, NULL, refine_foobar, Qnil);
}

但我觉得必须有一种方法可以rb_mod_refine直接调用而不是通过rb_block_call.

有任何想法吗?谢谢!

4

1 回答 1

1

在当前使用中,对模块进行了改进。它就在方法的名称中。

AFAIK,它不直接与块一起使用。

我能看到这个工作的唯一方法是在模块中创建一个“C”方法,然后使用 ruby​​ 代码以传统方式将该模块应用为改进。

于 2019-04-05T16:15:43.907 回答