From: Martin DeMello Date: 2009-06-12T22:55:19+09:00 Subject: Re: wrapping a C struct[] constant On Fri, Jun 12, 2009 at 5:12 PM, 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? Using it (or want to use it!) from the ruby side to generate a hash of constant => name and use that to unpack and display flag settings. m.