Module: FFI::DataConverter

Included in:
AutoPointer, Enum, StrPtrConverter
Defined in:
ext/ffi_c/DataConverter.c,
ext/ffi_c/DataConverter.c

Overview

This module is used to extend somes classes and give then a common API.

Most of methods defined here must be overriden.

Instance Method Summary (collapse)

Instance Method Details

- (value) from_native(value, ctx)

Convert from a native type.

Parameters:

  • value
  • ctx

Returns:

  • (value)


65
66
67
68
69
# File 'ext/ffi_c/DataConverter.c', line 65

static VALUE
conv_from_native(VALUE self, VALUE value, VALUE ctx)
{
    return value;
}

- (Type) native_type(type) - (Object) native_type

Get native type.

Overloads:

  • - (Type) native_type(type)

    Get native type from type.

    Parameters:

    • type (String, Symbol, Type)

    Returns:

  • - (Object) native_type

    Raises:

    • (NotImplementedError)

      This method must be overriden.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'ext/ffi_c/DataConverter.c', line 23

static VALUE
conv_native_type(int argc, VALUE* argv, VALUE self)
{
    if (argc == 0) {
        if (!rb_ivar_defined(self, id_native_type_ivar)) {
            rb_raise(rb_eNotImpError, "native_type method not overridden and no native_type set");
        }

        return rb_ivar_get(self, id_native_type_ivar);

    } else if (argc == 1) {
        VALUE type = rbffi_Type_Find(argv[0]);

        rb_ivar_set(self, id_native_type_ivar, type);

        return type;

    } else {
        rb_raise(rb_eArgError, "incorrect arguments");
    }
}

- (value) to_native(value, ctx)

Convert to a native type.

Parameters:

  • value
  • ctx

Returns:

  • (value)


52
53
54
55
56
# File 'ext/ffi_c/DataConverter.c', line 52

static VALUE
conv_to_native(VALUE self, VALUE value, VALUE ctx)
{
    return value;
}