diff ruby/rbdc/examples/unix_math.rb @ 0:0cfcc391201f

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:26:28 +0100
parents
children 5e159be89d73
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ruby/rbdc/examples/unix_math.rb	Thu Mar 19 22:26:28 2015 +0100
@@ -0,0 +1,25 @@
+#//////////////////////////////////////////////////////////////////////
+#
+#	unix_math.rb
+#	Copyright 2014 Tassilo Philipp
+#
+#	Dyncall sample loading libm and calling functions
+#
+#///////////////////////////////////////////////////////////////////////
+
+require 'rbdc'
+
+l = Dyncall::ExtLib.new
+if l.load('/usr/lib/libm.so') != nil and l.syms_init('/usr/lib/libm.so') != nil
+  puts 'Symbols in libm: '+l.syms_count.to_s
+  puts 'All symbol names in libm:'
+  l.syms_each { |s| puts s }
+
+  puts 'libm has sqrtf()? '       + l.exists?(:sqrtf)      .to_s
+  puts 'libm has pow()? '         + l.exists?(:pow)        .to_s
+  puts 'libm has not_in_libm()? ' + l.exists?(:not_in_libm).to_s
+
+  puts 'sqrtf(36.f) = '    + l.call(:sqrtf, 'f)f', 36.0)      .to_s
+  puts 'pow(2.0, 10.0) = ' + l.call(:pow,   'dd)d', 2.0, 10.0).to_s
+end
+