From: ES Date: 2005-05-10T00:56:46+09:00 Subject: Re: Problem with Math module in extension. Ernest Ellingson wrote: > George Ogata wrote: > >> Ernest Ellingson writes: >> >> >>> If you look at the Math_init() function it aliases the math_sin >>> function in Math.c as "sin" with 1 argument. However, (this is >>> where I become confused) the math_sin function seems to require 2 >>> inputs not one. >> >> >> >> In ruby, all functions -- even things that look like static member >> functions like Math.sin -- are methods of an object. Math.sin is a >> method of the Math object. >> >> Now, whenever you call a C function that's bound to a ruby method, one >> parameter is always the receiver of the call -- the "self". Nearly >> always, this is the first parameter of the C function. >> >> Combining the above two snippets of knowledge: >> >> To call math_sin() properly, the first argument should be the receiver >> of Math.sin: rb_mMath. (If you've looked at the source though, you'll >> probably realize that it doesn't really matter what you give as the >> first argument since Math.sin has no need to reference it.) >> >> >> > Thanks for the information. I still can't seem to get the syntax right > for calling Math.sin from an extension. I can do fine by calling > sin(RFLOAT(obj)->value). But I'm not calling the Math module. Just how > does one incorporate the Math module. > One of the big problems I have is that I can't find any documentation of > the Math module at > http://www.ruby-doc.org/doxygen/1.8.2/modules.html > Can some one give a short description of how you call math_sin from an > extension written in C ? > What are the necessary calls? Quickly and untestedly you would do something like VALUE val = // Value to get sin out of VALUE mMath = rb_get_const(rb_cObject, rb_intern("Math")); VALUE res = rb_funcall(mMath, rb_intern("sin"), 1, val); > Thanks, > Ernie E -- template void quack(duck& d) { d.quack(); }