diff options
author | wmeissner <devnull@localhost> | 2008-09-01 19:44:50 +1000 |
---|---|---|
committer | wmeissner <devnull@localhost> | 2008-09-01 19:44:50 +1000 |
commit | 65dd5c08e6c2dbfe467a3962a174f8d127fd30a1 (patch) | |
tree | e75d2a9e4386cc4afb81d80f7d9ff69065a547ca /samples | |
parent | d71d5d7329dcd0f30e62651a132b4227afc19fa5 (diff) | |
download | ffi-65dd5c08e6c2dbfe467a3962a174f8d127fd30a1.tar.gz |
Get basic FFI:Struct functionality up and running
Diffstat (limited to 'samples')
-rw-r--r-- | samples/gettimeofday.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/samples/gettimeofday.rb b/samples/gettimeofday.rb new file mode 100644 index 0000000..f9835b4 --- /dev/null +++ b/samples/gettimeofday.rb @@ -0,0 +1,12 @@ +require 'ffi' +class Timeval < FFI::Struct +# layout :tv_sec => :ulong, :tv_usec => :ulong + layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4 +end +module LibC + extend FFI::Library + attach_function :gettimeofday, [ :pointer, :pointer ], :int +end +t = Timeval.new +LibC.gettimeofday(t.pointer, nil) +puts "t.tv_sec=#{t[:tv_sec]} t.tv_usec=#{t[:tv_usec]}" |