A function pointer {Field} in a {StructLayout}.
static VALUE
function_field_get(VALUE self, VALUE pointer)
{
StructField* f;
Data_Get_Struct(self, StructField, f);
return rbffi_Function_NewInstance(f->rbType, (*rbffi_AbstractMemoryOps.pointer->get)(MEMORY(pointer), f->offset));
}
If a Proc is submitted as proc, it is automatically transformed to a {Function}.
static VALUE
function_field_put(VALUE self, VALUE pointer, VALUE proc)
{
StructField* f;
VALUE value = Qnil;
Data_Get_Struct(self, StructField, f);
if (NIL_P(proc) || rb_obj_is_kind_of(proc, rbffi_FunctionClass)) {
value = proc;
} else if (rb_obj_is_kind_of(proc, rb_cProc) || rb_respond_to(proc, rb_intern("call"))) {
value = rbffi_Function_ForProc(f->rbType, proc);
} else {
rb_raise(rb_eTypeError, "wrong type (expected Proc or Function)");
}
(*rbffi_AbstractMemoryOps.pointer->put)(MEMORY(pointer), f->offset, value);
return self;
}
Generated with the Darkfish Rdoc Generator 2.