Strategies for finding binary dependencies
1// https://blog.peterzhu.ca/ruby-c-ext-part-1/
2
3#include <signal.h>
4
5#include <ruby/ruby.h>
6
7static ID id_puts;
8
9static void kernel_puts(VALUE val)
10{
11 rb_funcall(rb_mKernel, id_puts, 1, val);
12}
13
14static VALUE foo(VALUE self)
15{
16 raise(SIGINT);
17 kernel_puts(self);
18
19 return Qnil;
20}
21
22void Init_methods(void)
23{
24 id_puts = rb_intern("puts");
25
26 rb_define_method(rb_cObject, "foo", foo, 0);
27}
28
29void Init_my_c_ext(void)
30{
31 ID id_puts = rb_intern("puts");
32
33 raise(SIGINT);
34 VALUE hello_world_str = rb_str_new_cstr("Hello world!");
35 rb_funcall(rb_mKernel, id_puts, 1, hello_world_str);
36}