Skip to content

Instantly share code, notes, and snippets.

@djberg96
Created October 16, 2010 04:18
Show Gist options
  • Save djberg96/629409 to your computer and use it in GitHub Desktop.
Save djberg96/629409 to your computer and use it in GitHub Desktop.
rake compiler test
# extconf.rb
require 'mkmf'
create_makefile('foo')
# foo.h
#ifndef __FOO_H_INCLUDED__
#define __FOO_H_INCLUDED__
#include <ruby.h>
extern VALUE cFoo;
extern VALUE cBar;
static VALUE rb_hash_aref2(VALUE v_hash, char* key){
VALUE v_key, v_val;
v_key = rb_str_new2(key);
v_val = rb_hash_aref(v_hash, v_key);
if(NIL_P(v_val))
v_val = rb_hash_aref(v_hash, ID2SYM(rb_intern(key)));
return v_val;
}
#endif
// foo.c
#include <foo.h>
static VALUE foo_alpha(VALUE v_hash){
VALUE v_hello = rb_hash_aref2(v_hash, "hello");
return v_hello;
}
void Init_foo(){
cFoo = rb_define_class("Foo", rb_cObject);
rb_define_method(cFoo, "alpha", foo_alpha, 1);
Init_bar();
}
// bar.c
#include <foo.h>
void Init_bar(){
cBar = rb_define_class("Bar", rb_cObject);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment