Académique Documents
Professionnel Documents
Culture Documents
Writing C Extension.
Sharing my personal experience, writing C
extension is a tough job and it an it advisable to go
with FFI dont use it, until you have no other
option. But, frankly speaking, I was scared of
writing C into widely used application.
Apart from FFI, there were great options like for
writing Ruby Extensions in Go, Crystal, Rust and
many other languages where C bindings can be
exposed. Anyways All I wanted to do is Go with C
extension.
clean C - rtosc
Considering several OSC and canonical
implementations, it made me use macros and
structs,which I didnt completely understand at the
time. I was about to give up and fortunately I
stumbled on the rtosc library. It is consisted with
two files rtosc.h and rtosc.c. Wishing the best
spirit of open source, I enquired on GitHub issue
and within few hours got a thoughtful and polite
response -viva la internet!
case T_FLOAT:
To convert from Ruby to C NUM2DBL
Strings and Symbols
case T_STRING:
To convert Ruby symbols use rb_sym_to_s().
Unicode Strings
I had broken Unicode strings. However it needs to
be fixed so did my job this way.
string_arg = rb_str_new2(string_from_c);
enc = rb_enc_find_index("UTF-8");
rb_enc_associate_index(string_arg, enc);
Ruby Time objects
Start with the object type
case T_DATA:
It means you have Ruby object and you can
specifically check using
if (CLASS_OF(current_arg) == rb_cTime)
further reading