comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:0cfcc391201f
1 #//////////////////////////////////////////////////////////////////////
2 #
3 # unix_math.rb
4 # Copyright 2014 Tassilo Philipp
5 #
6 # Dyncall sample loading libm and calling functions
7 #
8 #///////////////////////////////////////////////////////////////////////
9
10 require 'rbdc'
11
12 l = Dyncall::ExtLib.new
13 if l.load('/usr/lib/libm.so') != nil and l.syms_init('/usr/lib/libm.so') != nil
14 puts 'Symbols in libm: '+l.syms_count.to_s
15 puts 'All symbol names in libm:'
16 l.syms_each { |s| puts s }
17
18 puts 'libm has sqrtf()? ' + l.exists?(:sqrtf) .to_s
19 puts 'libm has pow()? ' + l.exists?(:pow) .to_s
20 puts 'libm has not_in_libm()? ' + l.exists?(:not_in_libm).to_s
21
22 puts 'sqrtf(36.f) = ' + l.call(:sqrtf, 'f)f', 36.0) .to_s
23 puts 'pow(2.0, 10.0) = ' + l.call(:pow, 'dd)d', 2.0, 10.0).to_s
24 end
25