From: Jason Roelofs Date: 2008-01-12T04:42:39+09:00 Subject: Re: Using ruby.h to generate C++ vectors and maps ------=_Part_3106_29543338.1200080564247 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Jan 11, 2008 2:12 PM, Edward Liu wrote: > I am trying to use ruby.h to extend Ruby with C/C++. I understand how > to deal with numbers and strings, but I am having trouble finding > documentation about vectors and maps. Let's say I have this function > for example: > > VALUE read_values(VALUE self, VALUE object); > > The 'object' variable can represent either a Ruby array or a Ruby hash. > If it is a Ruby array, I want to translate it to a vector. If it is a > Ruby hash, I want to translate it to a map. I know for integers, there > is a macro called NUM2INT that converts a Ruby number into a C/C++ > integer. For strings, I know that the function StringValueCStr does > what I want. I couldn't find it in the ruby.h documentation, but is > there any similar functionality in ruby.h for translating to vectors and > maps? If so, what is the functionality? If there is not a direct > translation, what would be the best approach to do my task? I'd like to > avoid using another protocol, like SWIG, for this task, if possible. > > Thanks, > Edward > -- > Posted via http://www.ruby-forum.com/. > > You'll want something like: VALUE read_values(VALUE self, VALUE object) { if(rb_obj_is_instance_of(object, "Hash") { } else if (rb_obj_is_instance_of(object, "Array") { } } API is best found here: http://www.rubycentral.com/pickaxe/ext_ruby.html Jason ------=_Part_3106_29543338.1200080564247--