Skip to content

Instantly share code, notes, and snippets.

@mfpiccolo
Created July 21, 2015 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfpiccolo/70923bef4a0cf62994f8 to your computer and use it in GitHub Desktop.
Save mfpiccolo/70923bef4a0cf62994f8 to your computer and use it in GitHub Desktop.
require 'ffi'
module Scrape
extend FFI::Library
ffi_lib './target/debug/libscrape.dylib'
class TwoNumbers < FFI::Struct
layout :first, :uint32,
:second, :uint32
end
attach_function :add_struct_vals, [TwoNumbers.by_value], :int32
attach_function :add_one_to_vals, [TwoNumbers.by_value], TwoNumbers.by_value
end
tn = Scrape::TwoNumbers.new
tn[:first] = 10
tn[:second] = 20
puts Scrape.add_struct_vals(tn) == 30 ? "Wooooo!" : "Booooooo!"
puts Scrape.add_one_to_vals(tn)[:first] == 11 ? "Wooooo!" : "Booooooo!"
puts Scrape.add_one_to_vals(tn)[:second] == 21 ? "Wooooo!" : "Booooooo!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment