From String to T_STRING

D

Detlef Reichl

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
 
E

Eric Hodel

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.

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().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top