From String to T_STRING

Hi,

i have a method, wich is called with type identifiers like this:

my_method(Sting, Fixnum)

this method is implemented in a C extension. In this extension it is
easy to get the name of the parameters with rb_class2name. But how can i
get the types like T_STRING or T_FIXNUM? If i use BUILTIN_TYPE or TYPE i
get T_CLASS.

Cheers, detlef

On Mar 25, 2008, at 06:24 AM, Detlef R. wrote:

TYPE i
get T_CLASS.

I’m guessing your C implementation looks something like:

my_method(VALUE a, VALUE b) {
}

Since you’ve passed in the String and Fixnum classes, the C type of
the RObject your VALUE points to is T_STRING. If you want an RObject
with a C type of T_STRING or T_FIXNUM you’ll have to pass in a String
object like “foo” or Fixnum like 5.

If your C function must be passed a String and a Fixnum object, you’ll
need to do duck-type checking, rb_check_string_type() and maybe
rb_Integer() or rb_to_int().

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs