module

DL

Importance_2
v1_9_3_125 - Show latest stable - 0 notes

A bridge to the dlopen() or dynamic library linker function.

Example

bash $> cat > sum.c <<EOF
double sum(double *arry, int len)
{
        double ret = 0;
        int i;
        for(i = 0; i < len; i++){
                ret = ret + arry[i];
        }
        return ret;
}

double split(double num)
{
        double ret = 0;
        ret = num / 2;
        return ret;
}
EOF
bash $> gcc -o libsum.so -shared sum.c
bash $> cat > sum.rb <<EOF
require 'dl'
require 'dl/import'

module LibSum
        extend DL::Importer
        dlload './libsum.so'
        extern 'double sum(double*, int)'
        extern 'double split(double)'
end

a = [2.0, 3.0, 4.0]

sum = LibSum.sum(a.pack("d*"), a.count)
p LibSum.split(sum)
EOF
bash $> ruby sum.rb
4.5

WIN! :-)

Constants

MAX_CALLBACK = Document-const

DLSTACK_SIZE = Document-const

RTLD_GLOBAL = Document-const: RTLD_GLOBAL rtld DL:

RTLD_LAZY = Document-const: RTLD_LAZY rtld DL:

RTLD_NOW = Document-const: RTLD_NOW rtld DL:

TYPE_VOID = Document-const: TYPE_VOID DL:

TYPE_VOIDP = Document-const: TYPE_VOIDP DL:

TYPE_CHAR = Document-const: TYPE_CHAR DL:

TYPE_SHORT = Document-const: TYPE_SHORT DL:

TYPE_INT = Document-const: TYPE_INT DL:

TYPE_LONG = Document-const: TYPE_LONG DL:

TYPE_LONG_LONG = Document-const: TYPE_LONG_LONG DL:

TYPE_FLOAT = Document-const: TYPE_FLOAT DL:

TYPE_DOUBLE = Document-const: TYPE_DOUBLE DL:

ALIGN_VOIDP = Document-const

ALIGN_CHAR = Document-const

ALIGN_SHORT = Document-const

ALIGN_INT = Document-const

ALIGN_LONG = Document-const

ALIGN_LONG_LONG = Document-const

ALIGN_FLOAT = Document-const

ALIGN_DOUBLE = Document-const

SIZEOF_VOIDP = Document-const

SIZEOF_CHAR = Document-const

SIZEOF_SHORT = Document-const

SIZEOF_INT = Document-const

SIZEOF_LONG = Document-const

SIZEOF_LONG_LONG = Document-const

SIZEOF_FLOAT = Document-const

SIZEOF_DOUBLE = Document-const

RUBY_FREE = Document-const

BUILD_RUBY_PLATFORM = Document-const

BUILD_RUBY_VERSION = Document-const

SEM = Mutex.new # :nodoc:

CdeclCallbackProcs = {}

CdeclCallbackAddrs = {}

StdcallCallbackProcs = {}

StdcallCallbackAddrs = {}

Attributes

Show files where this module is defined (11 files)
Register or log in to add new notes.