From String to T_STRING

Discussion in 'Ruby' started by Detlef Reichl, Mar 25, 2008.

  1. 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
     
    Detlef Reichl, Mar 25, 2008
    #1
    1. Advertisements

  2. Detlef Reichl

    Eric Hodel Guest

    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().
     
    Eric Hodel, Mar 26, 2008
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mladen Adamovic
    Replies:
    3
    Views:
    15,349
    Mladen Adamovic
    Dec 5, 2003
  2. Matt
    Replies:
    3
    Views:
    748
    Tor Iver Wilhelmsen
    Sep 17, 2004
  3. Bruce Sam
    Replies:
    15
    Views:
    8,611
    John C. Bollinger
    Nov 19, 2004
  4. =?Utf-8?B?UmFqZXNoIHNvbmk=?=

    'System.String[]' from its string representation 'String[] Array'

    =?Utf-8?B?UmFqZXNoIHNvbmk=?=, May 4, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,984
    =?Utf-8?B?UmFqZXNoIHNvbmk=?=
    May 4, 2006
  5. Earl Eiland
    Replies:
    3
    Views:
    723
    Peter Hansen
    May 16, 2005
  6. Fei Liu
    Replies:
    9
    Views:
    688
  7. =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    Replies:
    5
    Views:
    1,578
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    May 6, 2006
  8. Gary Wessle

    string.fine(string+string...

    Gary Wessle, Aug 16, 2006, in forum: C++
    Replies:
    5
    Views:
    371
    Old Wolf
    Aug 19, 2006
Loading...