K
K
KarlKremen2018-04-19 09:03:46
ruby
KarlKremen, 2018-04-19 09:03:46

Pass Ruby block as argument to CXX-extension?

It is necessary to declare a method in CXX-extension that would accept a Ruby block (in order to track the progress of the task). I use RICE binders .
Here is a class method in C++:

String PieceMaker::makeHash(void onProgress(int, int));

I want to pass a block to it from Ruby:
pm.make_hash do |done, total|
  # code goes here
end

But when compiling the extension, RIce doesn't know how to cast the argument.
/home/kkremen/.rvm/gems/ruby-2.5.1/gems/rice-2.1.2/ruby/lib/include/rice/detail/../detail/Caster.hpp:36:54: error: invalid static_cast from type ‘void*’ to type ‘void (*)(int, int)’
       Derived_T * d(static_cast<Derived_T *>(derived));
                                                      ^
/home/kkremen/.rvm/gems/ruby-2.5.1/gems/rice-2.1.2/ruby/lib/include/rice/detail/../detail/Caster.hpp:37:37: error: invalid static_cast from type ‘void (*)(int, int)’ to type ‘void*’
       return static_cast<Base_T *>(d);
                                     ^

What am I doing wrong and how can I make it work?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question