view ruby/rbdc/examples/unix_math.rb @ 46:c21d1c2c84e1

- removed pydc.py wrapper overhead (which only called pydcext.so functions, directly, anyways) * implies renaming pydcext.* to pydc.* * while at it, iterate directly over args that are passed in (before we did extract fptr, sig and a tuple for the args and iterated over latter afterwards); we might have a tiny perf improvement now - added type stub as package_data
author Tassilo Philipp
date Fri, 13 Nov 2020 14:10:31 +0100
parents 5e159be89d73
children
line wrap: on
line source

#//////////////////////////////////////////////////////////////////////
#
#	unix_math.rb
#	Copyright 2015 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