Ramrod
Ramrod

Reputation: 378

Wrapping a C function with FFI for Ruby

I admittedly struggle with C and C++, but I'm trying to wrap a C++ function (extern to 'C') in FFI but don't quite understand the syntax.

The form of the externed C code is:

Client *create_client(Address *address, const char * const foo){
//make stuff  
}

My question, specifically, is how to wrap that in Ruby using FFI? I think the constructor takes two pointers, so it would be of form:

attach_function :create_client, [:pointer, :pointer], :pointer

But, on the other hand, the const char * const foo confuses me - should it be treated as a string like so:

attach_function :create_client, [:pointer, :string], :pointer

Thanks.

Upvotes: 0

Views: 138

Answers (1)

x64architecture
x64architecture

Reputation: 409

attach_function :create_client, [:pointer, :string], :pointer

The const char * means its a c string the const part after only matters to the function your calling. See this for more details. The function you wrapped looks correct to me but im assuming you need more than this function which will be more complex.

The FFI wiki has some good info here.

Upvotes: 1

Related Questions