Subject: [ruby-ffi] MemoryPointers for ints? |
From: Chuck Remes |
Date: 5/6/10 12:05 PM |
To: ruby-ffi@googlegroups.com |
I'm just getting started with FFI, so forgive the newbie questions. I have a function prototype like so: int zmq_setsockopt (void *socket, int option_name, const void *option_value, size_t option_len); I've wrapped the library containing this function using the following #attach_function call: attach_function :zmq_setsockopt, [:pointer, :int, :pointer, :int], :int In C, this is called like this: setsockopt (context, ZMQ_SUBSCRIBE, "xy.z\x00", 5); OR int64_t rate = 10000; setsockopt (context, ZMQ_RATE, &rate, sizeof (rate)); In my ruby code, I think I need to create a MemoryPointer of some kind to pass as the 3rd parameter. The examples show the third parameter is sometimes an integer (100) or a string ("topic.string"). I know how to create a pointer from a string using MemoryPointer.from_string("topic.string") but I don't see how to handle the case when an integer is passed in. Related to this, I don't see how to execute #sizeof. I promise to update the wiki if the answers can prove generally useful. cr