I could really use the push in the right direction.
Given this C code:
typedef void cbfunc(void *data);
void set_callback(cbfunc* cb);
void do_stuff(void *data);
This Ruby Code:
module Lib
extend FFI::Library
callback :cbfunc, [:pointer], :void
attach_function :set_callback, [:cbfunc], :void
attach_function :do_stuff, [:pointer], :void
end
Is there a way to pass the ruby array as callback data, for example:
proc = Proc.new do |data|
data.push(5)
end
Lib::set_callback(proc)
Lib::do_stuff(ptr_to_a_ruby_obj_here)
The problem is that the callback will be called several times, and I need a way to easily build an array of different ruby objects.
I may be a little tired, but it seems to me that there is an easy way to do this, and I just do not see it.
source
share