関数をmrubyのブロックとして扱える。
mrb_value myfunc(mrb_state *mrb, mrb_value obj) {
printf("myfunc: start\n");
printf("myfunc: end\n");
return mrb_nil_value(); // プログラムに応じて返す
}
blk = mrb_proc_new_cfunc(mrb, myfunc);
proc = mrb_obj_value(blk);
val = mrb_funcall_with_block(mrb, mrb_top_self(mrb), mrb_intern_cstr(mrb, "mymethod"), 0, NULL, proc);
// mrb_funcall(mrb,mrb_top_self(mrb),"p",1,proc);
def mymethod(&blk)
p "Hello, this is mymethod."
yield
end
mrb_value block;
mrb_get_args(mrb, "&", &block);
mrb_value block;
mrb_value val;
mrb_yield(mrb, block, val);