A question about using inline.rb

Hi there,

Is there anyone has used inline.rb to extend ruby in c? Should i include the
header file
inside the class? and should i include them just like in c code? For example:
#include <unistd.h>
#include <signal.h>

Thanks,

Maggie

Hi There,

No one answer my question. :frowning: Can you help me for this simple question?
Thanks

···

----- Original Message -----
From: “Maggie Xiao” mxiao@ee.ualberta.ca
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, September 12, 2002 8:38 PM
Subject: a question about using inline.rb

Hi there,

Should i include the
header file
inside the class when I use rubyinline? and should i include them just
like in c code? For example:
#include <unistd.h>
#include <signal.h>

Thanks,

Maggie

Maggie Xiao wrote:

Hi there,

Is there anyone has used inline.rb to extend ruby in c? Should i
include the
header file
inside the class? and should i include them just like in c code? For
example:
#include <unistd.h>
#include <signal.h>

Thanks,

Maggie

I don’t know how inline.rb handles this, but cgenerator defines an
include method that you can call in the context of your function
definition (this is from examples/sample.rb):

lib.define(“distance”).instance_eval {
arguments “point *p1”, “point *p2”
return_type “double”
scope :extern
returns “sqrt(pow(p1->x - p2->x, 2) + pow(p1->y - p2->y, 2))”
include “<math.h>”
}

(This is just a C function, not a method, but cgenerator lets you define
methods, too.)

The include call propagates up to the library object, which generates
the appropriate code in its main header file, and checks if you have
already included <math.h>.

Ahh, stated this way I finally think I understand your question…
Good. I didn’t feel good with my last “huh?” response. :slight_smile:

Actually, the current version of inline is far too stupid to deal with
this, at least the way you’d expect. Actually, come to think of it, for
simple C headers, I guess it would not only work, but also be totally
legal. Let me explain with the following bogus call to inline:

class Blah
include Inline
def something(*args)
inline args, “some code”
end
end

becomes the C code:

#include <ruby.h>

static VALUE t_something(int argc, VALUE *argv, VALUE self) {
some code
}

VALUE cMod_Blah_something;

void Init_Mod_Blah_something() {
cMod_Blah_something = rb_define_module(“Mod_Blah_something”);
rb_define_method(cMod_Blah_something, “_something”, t_something,
-1);
}

Now, w/ a plain C header (no inlined code ala C++, no other weird fancy
stuff), it should(*) be perfectly legal to have #include INSIDE the
function, it will look weird, and nobody would every write a function
that way, but it should compile.

That said, I think it sucks and I think I’ll add an optional string for
extra includes or something… Suggestions? I’d like to keep the
signature relatively the same if possible, but changing the signature
right now won’t effect it too bad right now since it’s so new.

*) I could be wrong, verify w/ your local pedant.

···

On Thursday, Sep 12, 2002, at 19:38 US/Pacific, Maggie Xiao wrote:

Is there anyone has used inline.rb to extend ruby in c? Should i
include the
header file
inside the class? and should i include them just like in c code? For
example:
#include <unistd.h>
#include <signal.h>