123456789_123456789_123456789_123456789_123456789_

Class: FFI::StructLayout::Function

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Field
Instance Chain:
self, Field
Inherits: FFI::StructLayout::Field
Defined in: ext/ffi_c/StructLayout.c

Overview

A function pointer Field in a ::FFI::StructLayout.

Class Method Summary

Field - Inherited

Instance Method Summary

Field - Inherited

Constructor Details

This class inherits a constructor from FFI::StructLayout::Field

Instance Method Details

#get(pointer) Get(a {Function} from memory pointed by +pointer+.)

[ GitHub ]

  
# File 'ext/ffi_c/StructLayout.c', line 304

static VALUE
function_field_get(VALUE self, VALUE pointer)
{
    StructField* f;

    TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, f);

    return rbffi_Function_NewInstance(f->rbType, (*rbffi_AbstractMemoryOps.pointer->get)(MEMORY(pointer), f->offset));
}

#put(pointer, proc) Set(a {Function} to memory pointed by +pointer+ as a function.)

If a Proc is submitted as proc, it is automatically transformed to a Function.

[ GitHub ]

  
# File 'ext/ffi_c/StructLayout.c', line 323

static VALUE
function_field_put(VALUE self, VALUE pointer, VALUE proc)
{
    StructField* f;
    VALUE value = Qnil;

    TypedData_Get_Struct(self, StructField, &rbffi_struct_field_data_type, 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;
}