Subject:
[ruby-ffi] Pointer to a struct - how to cast?
From:
Drew
Date:
5/20/10 10:14 AM
To:
ruby-ffi

Hi there, I have a pointer to a struct that looks like this:

// c:
typedef struct
	{
	 IntT offset;
	 IntT dataType;
	 union {
		StringT sdata;
		IntT idata;
		} u;
	} F_TextItemT;

In Ruby I've defined it like this:

  class FTextItemU < FFI::Union
    layout :sdata, :string,
    :idata, :int
  end

  class FTextItemT < FFI::Struct
    layout :offset, :int,
      :dataType, :int,
      :u, FTextItemU
  end

I'm trying to cast the pointer like this:

my_struct = FM::FTexFtItemT.new(p)
puts "test: #{my_struct[:dataType]}"

However, I'm getting a seg fault on the puts statement.

Any ideas of what I'm doing wrong?

Thanks!
Drew