[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

From String to T_STRING

Detlef Reichl

3/25/2008 1:25:00 PM

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


1 Answer

Eric Hodel

3/26/2008 10:00:00 PM

0

On Mar 25, 2008, at 06:24 AM, Detlef Reichl wrote:
> 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().