Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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);
- }
Add Comment
Please, Sign In to add comment