Calling a custom Ruby C extension method from other C extension

Discussion in 'Ruby' started by Iñaki Baz Castillo, Apr 19, 2011.

  1. Hi, in my project I've created two Ruby C extensions:

    ext/my-exten/
    ext/string/

    They create my-create.so and string.so.

    string.so contains some custom methods I've added to class String
    (i.e. String#headerize).
    my-exten.so creates its own class and internally it needs to use the
    String#headerize method by directly calling the C method in the string
    extension (String_headerize).

    So I suposse I must create a ext/string/string.h file declaring the C
    function String_headerize, and use #include "../string/string.h"
    within my-exten.c. This should work but, is there any other approach?
    (note: I don't want to invoke a Ruby method from C code).

    Thanks a lot.

    --=20
    I=C3=B1aki Baz Castillo
    <>
    Iñaki Baz Castillo, Apr 19, 2011
    #1
    1. Advertising

  2. method 1:

    in your my-exten use "extern String_headerize( args );"
    and then you must require your string lib before yours

    method 2:

    if you not need the directly C method you chould use
    rb_funcall(string,rb_intern(headerize),args ...);

    --
    Posted via http://www.ruby-forum.com/.
    Hans Mackowiak, Apr 20, 2011
    #2
    1. Advertising

  3. 2011/4/20 Hans Mackowiak <>:
    > method 1:
    >
    > in your my-exten use "extern String_headerize( args );"
    > and then you must =C2=A0require your string lib before yours



    > method 2:
    >
    > if you not need the directly C method you chould use
    > rb_funcall(string,rb_intern(headerize),args ...);



    Thanks a lot. I prefer method 1 (as I expect is faster than method 2).


    --=20
    I=C3=B1aki Baz Castillo
    <>
    Iñaki Baz Castillo, Apr 20, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonah Olsson
    Replies:
    1
    Views:
    564
    Scott Allen
    Apr 5, 2005
  2. Dave
    Replies:
    0
    Views:
    445
  3. Erik
    Replies:
    11
    Views:
    637
    Peter Duniho
    Mar 29, 2008
  4. Jonah Olsson
    Replies:
    2
    Views:
    189
    Jonah Olsson
    Apr 5, 2005
  5. Zvt.Fred
    Replies:
    17
    Views:
    317
    Garrett Smith
    Apr 13, 2009
Loading...

Share This Page