summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorwmeissner <devnull@localhost>2008-09-01 19:44:50 +1000
committerwmeissner <devnull@localhost>2008-09-01 19:44:50 +1000
commit65dd5c08e6c2dbfe467a3962a174f8d127fd30a1 (patch)
treee75d2a9e4386cc4afb81d80f7d9ff69065a547ca /samples
parentd71d5d7329dcd0f30e62651a132b4227afc19fa5 (diff)
downloadffi-65dd5c08e6c2dbfe467a3962a174f8d127fd30a1.tar.gz
Get basic FFI:Struct functionality up and running
Diffstat (limited to 'samples')
-rw-r--r--samples/gettimeofday.rb12
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]}"