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. Advertising

  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. Advertising

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:
    0
    Views:
    755
    Mladen Adamovic
    Dec 4, 2003
  2. Mladen Adamovic
    Replies:
    3
    Views:
    14,680
    Mladen Adamovic
    Dec 5, 2003
  3. Matt
    Replies:
    3
    Views:
    530
    Tor Iver Wilhelmsen
    Sep 17, 2004
  4. Bruce Sam
    Replies:
    15
    Views:
    7,984
    John C. Bollinger
    Nov 19, 2004
  5. =?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,808
    =?Utf-8?B?UmFqZXNoIHNvbmk=?=
    May 4, 2006
Loading...

Share This Page