Subject:
Re: [ruby-ffi] changing array over struct with ruby ffi
From:
Matijs van Zuijlen
Date:
9/18/11 12:49 AM
To:
ruby-ffi@googlegroups.com

Hi Dor,

My advice would be to first get things working using the struct classes you defined directly, so something like

    result = foo(your_list)
    size = your_list[:size]
    ...

(It seems your layout for NodeList is not correct in the code below, by the way). This will look more like C than Ruby, I suppose.

Once you get that working, you can think about wrapping that code in some wrapper classes so you can present a Ruby-like interface to the rest of the program.

Regards,
Matijs.

On 09/05/2011 06:04 PM, Dor Kalev wrote:
Hi there!
I have this data

typedef struct {
   unsigned int size;
   unsigned int e[8];
} SmallAry;

typedef struct {
   unsigned int title;
   SmallAry form;
} Node;

typedef struct {
   Node * e;
   unsigned int size;
} NodeList;

int foo(NodeList * states);


module Foon
   class SAry<  FFI::Struct
     layout :size,  :pointer,
            :e,     :pointer
   end
   class Node<  FFI::Struct
     layout :title,  :int,
            :e,      SAry
   end
   class NodeList<  FFI::Struct
     layout :title,  :int,
            :e,      :pointer
   end
   extend FFI::Library
   ffi_lib "foon.so"
   attach_function :create_object, [], :pointer
   attach_function :foo, [ :pointer ], :int
end

I need foo to update the NodeList it gets and return it to Ruby so I
can use it,
help will be much appreciated.

thanks,
DK


-- 
Matijs