From: Eric Wong Date: 2012-05-10T05:48:00+09:00 Subject: Re: How to use Data_Wrap_Struct to assign the DATA VALUE to an exsiting Ruby object? I単aki Baz Castillo wrote: > Hi, my code receives an arbitrary klass name (provided by the user) > and I need to create an instance of such a klass and also wrap a C > pointer within it. > > Unfortunately Data_Wrap_Struct(VALUE class, void (*mark)(), void > (*free)(), void *ptr") requires a class VALUE rather than a single > object/instance. So I expect that I *cannot* attach/wrap a C DATA > pointer into an *existing* Ruby object and, instead, I need to store > the DATA pointer within an internal attribute of the object, am I > right? Ruby itself uses this idiom in some places: DATA_PTR(self) = ptr; Seriously, the best way to learn C extensions is to read Ruby itself (and its C extensions).