Subject:
[ruby-ffi] Re: Array of Ints
From:
John Lee
Date:
10/26/11 1:46 PM
To:
ruby-ffi

Thanks a lot. Your code really helped!

On Oct 26, 9:35 am, Chuck Remes <cremes.devl...@mac.com> wrote:
> 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/libzm...
>
> I call that function here:
>
> https://github.com/chuckremes/ffi-rzmq/blob/master/lib/ffi-rzmq/poll....
>
> 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_...
>
> 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