Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > From String to T_STRING

Reply
Thread Tools

From String to T_STRING

 
 
Detlef Reichl
Guest
Posts: n/a
 
      03-25-2008
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


 
Reply With Quote
 
 
 
 
Eric Hodel
Guest
Posts: n/a
 
      03-26-2008
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().

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'System.String[]' from its string representation 'String[] Array' =?Utf-8?B?UmFqZXNoIHNvbmk=?= ASP .Net 0 05-04-2006 04:29 PM
Is "String s = "abc";" equal to "String s = new String("abc");"? Bruce Sam Java 15 11-19-2004 06:03 PM
String[] files = {"a.doc, b.doc"}; VERSUS String[] files = new String[] {"a.doc, b.doc"}; Matt Java 3 09-17-2004 10:28 PM
String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 3 12-05-2003 04:20 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM



Advertisments