Subject: Re: [ruby-ffi] Re: Array of Ints |
From: Chuck Remes |
Date: 10/26/11 10:35 AM |
To: ruby-ffi@googlegroups.com |
On Oct 26, 2011, at 10:31 AM, John Lee wrote:
I tried wrapping my code inside a module, but the problem still persists. Do you think :pointer is the correct type to represent the array in attach_function. I know that if you have an array in a struct, you can specify it as: class Struct1 < ::FFI::Struct layout :value1, [:int, 3] end So I tried to replace :pointer with [:int, 3] in attach_function, but it complains about "unable to resolve type ':int, 3]' <TypeError>" attach_function :function1, [[:int, 3], :int, :int], :int Has anyone got arrays to work with FFI?
I have gotten it working in my own project. Take a look at my definition for a function that takes an array: https://github.com/chuckremes/ffi-rzmq/blob/master/lib/ffi-rzmq/libzmq.rb#L102 I call that function here: https://github.com/chuckremes/ffi-rzmq/blob/master/lib/ffi-rzmq/poll.rb#L44 The array that is passed to that function is constructed in this file: https://github.com/chuckremes/ffi-rzmq/blob/master/lib/ffi-rzmq/poll_items.rb In that file, the #clean method is where most of the array work is done where I construct the array. I know it's a big example, but it works and has worked without change since the ffi gem was at 0.6.3. cr