From: Jason Roelofs Date: 2009-06-12T22:31:33+09:00 Subject: Re: wrapping a C struct[] constant --000325572b82fb3461046c26b968 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Fri, Jun 12, 2009 at 7:42 AM, Eero Saynatkari wrote: > Martin DeMello wrote: > > I have some C code with a struct definition > > > > struct flag_str { > > unsigned int val; > > const char *str; > > }; > > > > and an inline array > > > > struct flag_str extent_flags[] = { > > { FIEMAP_EXTENT_LAST, "last" }, > > { FIEMAP_EXTENT_UNKNOWN, "unkown" }, > > { FIEMAP_EXTENT_DELALLOC, "delalloc" }, > > { FIEMAP_EXTENT_NO_BYPASS, "no_bypass" }, > > { FIEMAP_EXTENT_SECONDARY, "secondary" }, > > { FIEMAP_EXTENT_NET, "net" }, > > { FIEMAP_EXTENT_DATA_COMPRESSED, "data_compressed" }, > > { FIEMAP_EXTENT_DATA_ENCRYPTED, "data_encrypted" }, > > { FIEMAP_EXTENT_NOT_ALIGNED, "not_aligned" }, > > { FIEMAP_EXTENT_DATA_INLINE, "data_inline" }, > > { FIEMAP_EXTENT_DATA_TAIL, "data_tail" }, > > { FIEMAP_EXTENT_UNWRITTEN, "unwritten" }, > > { FIEMAP_EXTENT_MERGED, "merged" }, > > { 0, NULL }, > > }; > > > > What's the simplest way to expose that array as a ruby constant (other > > than just copy/pasting the data, of course :))? > > How/where are you *using* it? > > FFI is generally a good solution, although it > would probably be best to actually define the > Array on the Ruby side and pass it in as needed. > > > Eero > -- > Magic is insufficiently advanced technology. > -- > Posted via http://www.ruby-forum.com/. > > Even using FFI, you'll need to define the wrapping between C constant to Ruby constant, and using Ruby's API, you'll be define_const-ing every one of those, then putting them into an array. Just define them in the Ruby yourself, there isn't a faster way to do it. Jason --000325572b82fb3461046c26b968--