annotate ruby/rbdc/examples/unix_math.rb @ 66:7a61dd082341 default tip

pydc: - fix double free triggered by capsule destructor, when freeing pydc and callback objects, manually
author Tassilo Philipp
date Fri, 24 May 2024 18:16:29 +0200
parents 5e159be89d73
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 #//////////////////////////////////////////////////////////////////////
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 #
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 # unix_math.rb
1
5e159be89d73 - ruby and sh binding updates for dc r0.9
cslag
parents: 0
diff changeset
4 # Copyright 2015 Tassilo Philipp
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 #
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 # Dyncall sample loading libm and calling functions
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 #
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 #///////////////////////////////////////////////////////////////////////
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 require 'rbdc'
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 l = Dyncall::ExtLib.new
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 if l.load('/usr/lib/libm.so') != nil and l.syms_init('/usr/lib/libm.so') != nil
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 puts 'Symbols in libm: '+l.syms_count.to_s
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 puts 'All symbol names in libm:'
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 l.syms_each { |s| puts s }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 puts 'libm has sqrtf()? ' + l.exists?(:sqrtf) .to_s
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 puts 'libm has pow()? ' + l.exists?(:pow) .to_s
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 puts 'libm has not_in_libm()? ' + l.exists?(:not_in_libm).to_s
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 puts 'sqrtf(36.f) = ' + l.call(:sqrtf, 'f)f', 36.0) .to_s
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 puts 'pow(2.0, 10.0) = ' + l.call(:pow, 'dd)d', 2.0, 10.0).to_s
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 end
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25