The C function I am trying to call from Ruby is like this:
void foo(double *in_array, double *out_array)
where:
in_array
is an array of arrays that will be used by "foo" to calculate and return:out_array
which is also an array of arrays, and the C function will alter its content.
My wrapper looks like this:
module FooLib
extend FFI::Library
ffi_lib "foo.so"
attach_function :Foo, [:pointer, :pointer], :void
end
And I am doing the following in Ruby:
# Allocate the objects and prepare them
in_array = Matrix.build(10, 3) { rand }.to_a
out_array = Matrix.build(10, 3) { 0 }.to_a
FooLib.Foo(in_array, out_array)
But I get the following error:
:pointer argument is not a valid pointer (ArgumentError)
I can understand I need to use pointers to these arrays instead of the array objects, but I am not sure how to do this. Does it mean I need to create these structures in C using a LibC wrapper?