Skip to content

Instantly share code, notes, and snippets.

@vaiorabbit
Created August 17, 2013 15:23
Show Gist options
  • Select an option

  • Save vaiorabbit/6257411 to your computer and use it in GitHub Desktop.

Select an option

Save vaiorabbit/6257411 to your computer and use it in GitHub Desktop.
Ruby2.0標準ライブラリ・FiddleでDLLの関数を呼ぶテスト libRMath3D.dylib (https://github.com/vaiorabbit/rmath3d) の RVec4SetElements をRubyから呼ぶところまで。 ruby-ffi で似たことをやったときの記録→ http://gist.github.com/vaiorabbit/6048201
# Ref.: http://doc.ruby-lang.org/ja/2.0.0/library/fiddle=2fimport.html
require 'fiddle'
require 'fiddle/import'
module RMath3D
extend Fiddle::Importer
dlload Fiddle.dlopen( 'libRMath3D.dylib' )
RVec4 = struct ['double x', 'double y', 'double z', 'double w']
extern 'void RVec4SetElements( void*, double, double, double, double )'
end
if __FILE__ == $0
v = RMath3D::RVec4.malloc
v.x = v.y = v.z = v.w = 0.0
puts "v.x=#{v.x}, v.y=#{v.y}, v.z=#{v.z}, v.w=#{v.w}"
RMath3D::RVec4SetElements( v, 1, 2, 3, 4 )
puts "v.x=#{v.x}, v.y=#{v.y}, v.z=#{v.z}, v.w=#{v.w}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment