Module NativeSyllableComposer
In: lib/ext/native_syllable_composer/native_syllable_composer.c

// cf. www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html // cf. cesare.seesaa.net/article/32850625.html include "ruby.h" include "compose.h" VALUE syllable_composer = Qnil;

void Init_native_syllable_composer(); VALUE native_syllable_composer_compose(VALUE self, VALUE rInputType, VALUE rOutputType, VALUE rSyllable, VALUE rForcePOJStyleOutput);

void Init_native_syllable_composer() {

        syllable_composer = rb_define_module("NativeSyllableComposer");
        rb_define_singleton_method(syllable_composer, "compose", native_syllable_composer_compose, 4);

}

VALUE native_syllable_composer_compose(VALUE self, VALUE rInputType, VALUE rOutputType, VALUE rSyllable, VALUE rForcePOJStyleOutput) {

        int inputType = NUM2INT(rInputType);
        int outputType = NUM2INT(rOutputType);
    int forcePOJStyleOutput = NUM2INT(rForcePOJStyleOutput);

        VALUE rStr = StringValue(rSyllable);

        size_t rStrLen = RSTRING(rStr)->len;
        char *rStrPtr = RSTRING(rStr)->ptr;

        if (!rStrPtr) return Qnil;

        char *string = (char*)calloc(1, rStrLen + 1);
        memcpy(string, rStrPtr, rStrLen);

        VALUE result = ComposeTLSyllable(inputType, outputType, string, forcePOJStyleOutput);
        free(string);

        return result;

}

[Validate]