Subject:
Re: [ruby-ffi] Array of Ints
From:
Chuck Remes
Date:
10/25/11 5:25 PM
To:
ruby-ffi@googlegroups.com


On Oct 25, 2011, at 3:51 PM, John Lee wrote:

> I am  using Ruby 192
> 
> I have the following c function:
> 
> int function1(int *dataArray, int value1 , int value2)
> The first argument is an array of ints
> 
> 
> Here is my FFI code:
> attach_function :function1, [:pointer, :int, :int], :int
> ruby_array =  FFI::MemoryPointer.new(:int,4)
> ruby_array.write_array_of_int(1000,2000,3000,4000])
> 
> ...
> function1(ruby_array, 1, 2)
> 
> But that produces an error message that function1 is an  undefined
> method.

Try wrapping your FFI code up in a module. 

e.g.
module MyLibrary
  ffi_libs(path_to_lib)

  attach_function :function1, [:pointer, :int, :int], :int
end

MyLibrary.function1(ruby_array, 1, 2)

cr