From: "Asbjørn Reglund Thorsen" Date: 2005-01-28T02:41:43+09:00 Subject: Re: [Newbie] Extending Ruby ---259931839-127852608-1106847681=:1262 Content-Type: MULTIPART/MIXED; BOUNDARY="-259931839-127852608-1106847681=:1262" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---259931839-127852608-1106847681=:1262 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Thank you Lyle !! It really helps. :-) Think I am getting the hang of it now. On Thu, 27 Jan 2005, Lyle Johnson wrote: > On Fri, 28 Jan 2005 01:56:24 +0900, Asbj=F8rn Reglund Thorsen > wrote: > >> I am quite new to extending Ruby, and I have read the README.EXT. >> I am wondering how to translate (from the code below): >> "PyList_SetItem($result, i, PyFloat_FromDouble((double) p(i+1)));" >> Into Extending Ruby syntax. > > The (roughly) equivalent code in a Ruby extension would be: > > $result =3D rb_ary_new2(size); > for (int i =3D 0; i < size; i++) > rb_ary_store($result, i, rb_float_new((double) p(i+1))); > > Note that in Ruby you construct an Array instance with a certain > initial size by calling rb_ary_new2(size), and then you set the array > items by calling rb_ary_store(). Also, the function for constructing a > Ruby Float object from a C double is rb_float_new(). > > Hope this helps, > > Lyle > ---259931839-127852608-1106847681=:1262-- ---259931839-127852608-1106847681=:1262--