Daniel Berger wrote:
> Hi,
> 
> I'm trying to get better at FFI, but I'm getting stumped on how to
> create and pass pointers to functions.
> 
> In the example below, in the Sys::Uptime.seconds method, I'm trying to
> figure out how to create and pass a pointer for the mib (a 2-element
> integer array) and the timeval size (i.e. where I have a '?' instead of
> actual code).
> 
> What should the actual code be?

You could explicity instantiate two MemoryPointer objects initialized 
with
the proper values:

  mib_ptr = FFI::MemoryPointer.new(:int, 2).write_array_of_int(mib)
  tv_size_ptr = FFI::MemoryPointer.new(:int).write_int(tv.size)

Then you could pass those values to sysctl function:

  sysctl(mib_ptr, 2, tv, tv_size_ptr, nil, 0)

To ask for more (and better) help feel free to post your questions to 
the Ruby-FFI ml at users / ruby-ffi.kenai.com
-- 
Posted via http://www.ruby-forum.com/.