Skip to content

dsci/ruby-c-extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby C-API

Ruby is extendable with C. And I wanted to know how.

It covers defining classes, subclassing and calling a block.

Usage

Install required gems first

bundle install

Compile the extension:

rake compile[:ary]

Run the test suite

rake test

What else?

By the way, this is also possible with C++. The thing you have to do is, mark your Ruby extension entry function as extern.

/* a C++ header file. */
#include <ruby.h>

VALUE cTest;

/* a C++ source file. */
#include "hello.h"

extern "C" void Init_hello(){
  cTest = rb_define_class("MyTest", rb_cObject);
} 

In Ruby it is:

class MyTest
end

Author : Daniel Schmidt (dsci@code79.net)

Feel free to modify.

About

Just playing around with <ruby.h>

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published