Skip to content

Instantly share code, notes, and snippets.

@mzumi
Created November 2, 2016 11:46
Show Gist options
  • Save mzumi/c0b5aaf6b50d033ca3a92bb9907a94bf to your computer and use it in GitHub Desktop.
Save mzumi/c0b5aaf6b50d033ca3a92bb9907a94bf to your computer and use it in GitHub Desktop.
require 'ffi'
module FFISample
extend FFI::Library
ffi_lib 'target/release/libffi_sample.dylib'
class SampleStruct < FFI::Struct
layout :i, :int,
:b, :bool,
:s, :string
end
attach_function :create_sample_struct, [:pointer], :void
end
st = FFISample::SampleStruct.new
FFISample.create_sample_struct(st.pointer)
puts "i: #{st[:i]}, b:#{st[:b]}, s:#{st[:s]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment