Hi Matj P,

On 19/01/12 19:55, Matj P. wrote:
> Thank you Garth for your answer.
> I figured out the problem with segfault. It was caused by shared
> parametr in make file.
> I will try to embeded Ruby in C.
> So your opinion is that Data_Wrap_Struct should work also for nested
> structs? Do you have any experience with it?

Data_Wrap_Struct essentially bundles up any C pointer into a Ruby 
object. Thus anything that you can create a reference or pointer to, you 
can use it for. Ruby on its own can't do anything with it, but you can 
supply methods that act upon it on the C side. Like any pointer though, 
if you need to clean up the resource it points to, you have to make sure 
that *something* is performing the required cleanup. So yes, it's 
perfectly fine for nested structures, if I understand you correctly.

For my own project, I have Data_Wrap_Struct in use under an abstraction 
layer that I've written. The call that triggers Data_Wrap_Struct in my 
code is used *extensively*, so in answer to your question, yes, I have 
direct experience with it. I use it to manage a huge number of different 
C++ objects, including appropriate cleanup, etc. Some of these objects 
are highly complex- from the point of view of the Ruby code though, it's 
just a pointer to an opaque object. I have layered my own type 
management system on top of that, but you may not need to do this in 
your case. Once I'd gotten everything working correctly, it has been 
quite stable.

Garth