ruby c extension internal structure -


readme.ext, linked in ruby guides 1 of main resources develop ruby extensions, states following:

notice ruby not allow arbitrary pointer values value. should pointers structures ruby knows about. known structures defined in <ruby.h>.

so,

  1. how can hold arbitrary structure in object, without expose it?
  2. is there more complete resource 1 cited on ruby guides? while can go in ruby c code find functions need call, hard find direct answers code above on source code.

thanks!

this covers basics, including how use c structures managed exposure ruby objects, how macros , functions work, , reference many of functions: http://media.pragprog.com/titles/ruby3/ext_ruby.pdf

how manage c objects associated ruby ones depends partly on relationship want establish. create regular ruby objects within c, , speed 1 or 2 bits of complex maths instance. you'd work more values, @ least on input methods. access of ruby's dynamics , introspection way, have extension worked on instance variables finding of interest in object without knowing in advance called.

however, there macros , helper functions ruby.h hooking ruby's garbage collection c structs , arbitrary c data - types managed via malloc. example data_wrap_struct function allows create object c struct when process in extension, otherwise handled regular ruby object (for assignment variables etc). see cd jukebox example in document linked - there several related functions need use ensure code plays correctly ruby's memory management.


Comments