Basic FFI usageBefore diving into the details of the FFI API, lets take a look at a few examples demonstrating the simplicity of the FFI API usage for regular tasks.
例1 Calling a function from shared library 上の例の出力は以下となります。 Hello world!
例2 Calling a function, returning a structure through an argument 上の例の出力は、 たとえば以下のようになります。
int(0)
int(1555946835)
object(FFI\CData:struct timezone)#3 (2) {
["tz_minuteswest"]=>
int(0)
["tz_dsttime"]=>
int(0)
}
例3 Accessing existing C variables 上の例の出力は以下となります。 int(0)
例4 Creating and Modifying C variables 上の例の出力は以下となります。 int(0) int(5) int(7)
例5 Working with C arrays 上の例の出力は以下となります。 int(25) int(523776) int(1024) int(8192)
例6 Working with C enums 上の例の出力は以下となります。 int(0) int(2) int(3) |