Created
July 21, 2015 06:33
-
-
Save mfpiccolo/70923bef4a0cf62994f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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