Calling a custom Ruby C extension method from other C extension

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

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
<[email protected]>
 
H

Hans Mackowiak

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 ...);
 
I

Iñaki Baz Castillo

2011/4/20 Hans Mackowiak said:
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
<[email protected]>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top