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.
Example #1 Calling a function from shared library
The above example will output: Hello world!
Example #2 Calling a function, returning a structure through an argument
The above example will output something similar to: int(0) int(1555946835) object(FFI\CData:struct timezone)#3 (2) { ["tz_minuteswest"]=> int(0) ["tz_dsttime"]=> int(0) }
Example #3 Accessing existing C variables
The above example will output: int(0)
Example #4 Creating and Modifying C variables
The above example will output: int(0) int(5) int(7)
Example #5 Working with C arrays
The above example will output: int(25) int(523776) int(1024) int(8192)
Example #6 Working with C enums
The above example will output: int(0) int(2) int(3) |