Skip to content

Instantly share code, notes, and snippets.

@bernEsp
Last active August 29, 2015 14:09
Show Gist options
  • Save bernEsp/954d4c9514e87300c84c to your computer and use it in GitHub Desktop.
Save bernEsp/954d4c9514e87300c84c to your computer and use it in GitHub Desktop.
write c extension
-gem mongo_kerberos-example
ruby data types (18) ruby core objects
t_nil
t_object
t_class
t_string -> RString(c data type) <- RSTRING(functions)
t_array -> RArrray <- RARRAY
t_false
t_symbol
interacting with data types
1- check the type
2- convert VALUE into C data
How to check the type?
TYPE(VALUE valu)
Check_Type(Value value, int type)
c to ruby
1. cast to VALUE
2. use functions
3. wrap data
3/ encapsulate c data into ruby object
VALUE context;
context = Data?Wrap_Struct(rb_cObject, NULL, sasl_conn_free, conn)-> GarbageCcolector marker (object, gc, when liberate, )
rb_iv_set(self, "@context", context); how ruby code access this data
include ext with your gem
1) extconf.rb is better to have gem dependenci exception
inspect env and generate C makefile
2)rake compile task
task to build the extension(for testing, etc)
3)gemspec
include extension files and specify that the gem has an ext.
4)the c code
void Init_csassl(){
rb_define_method();
}
extension dependency == gem dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment