0
if (RARRAY_LEN(arr) > 0) 
   {
     VALUE str = rb_ary_entry(arr, 0);
     abc = some_method(*str);
   }

rb_ary_entry(arr, 0) gives me an index value. Then I want to convert that value to a string so I can pass it to the next method. I tried:

rb_str_new2(rb_ary_entry(arr, 0));

but I get error saying:

error: indirection requires pointer operand `('VALUE' (aka 'unsigned long')` `invalid`)`
`ipDict = some_method(*str)`;
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
mandss
  • 91
  • 6
  • `rb_ary_enrty` returns a `VALUE`, which could be a Ruby string. What is the signature of `some_method`, is it expecting a Ruby String (i.e. a `VALUE`) or a C string (i.e. a `char*`)? – matt Dec 09 '14 at 16:53
  • it is expecting a c String – mandss Dec 09 '14 at 20:54

1 Answers1

0

Use the StringValueCStr macro to convert a Ruby String into a char* (the rb_str_new functions are for converting in the other direction).

VALUE str = rb_ary_entry(arr, 0); // str is now a Ruby String
char *c_str = StringValueCStr(str);

abc = some_method(c_str);
matt
  • 78,533
  • 8
  • 163
  • 197