JRuby 1.1.5 FFI attach_method arg order

Just starting to play with FFI on my Win32 box…after reading a few of
the blog posts mentioned in Charlie’s
http://blog.headius.com/2008/10/ffi-for-ruby-now-available.html post I’m
seeing that the arg order to attach_method may be different than
documented.

It appears that if you want to have a Ruby module method named
differently than the native function you need to use this format

attach_function(ruby_name, native_name, arg_types_array, return_type)

rather than first specifying the native fcn name and then the ruby name.

Did I misread the source code docs and the blogs wrt arg order? What’s
the real API that will be used by the ‘ffi’ gem as well as JRuby?

Jon

SAMPLE CODE (Win32)

require ‘ffi’

module Win32
extend FFI::Library

ffi_lib :user32
ffi_convention :stdcall

attach_function :message_box, :MessageBoxA, [ :pointer, :string,
:string, :uint ], :int
end

rc = Win32.message_box(nil, ‘Hello World!’, ‘Some Title’, 2)
puts “Return code: #{rc}”

boom…

Win32.MessageBoxA(nil, ‘Hello World Again!’, ‘Another Title’, 2)


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

It appears that if you want to have a Ruby module method named differently than the native function you need to use this format

attach_function(ruby_name, native_name, arg_types_array, return_type)

Yep, thats the correct format. We changed it sometime before 1.1.4
shipped (which was the first version with FFI support). All versions
of CRuby FFI use the new format.

Thanks for the confirmation. More importantly, THANKS for all the
work on this and the CRuby gem which I’m anxious to see sometime sprout
a pre-built native extension for Win32 usage.

Looking forward to how your post-JNA efforts unfold at
http://code.google.com/p/jffi/


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

2008/11/18 Jon [email protected]:

It appears that if you want to have a Ruby module method named differently than the native function you need to use this format

attach_function(ruby_name, native_name, arg_types_array, return_type)

Yep, thats the correct format. We changed it sometime before 1.1.4
shipped (which was the first version with FFI support). All versions
of CRuby FFI use the new format.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email