Forum: JRuby JRuby 1.1.5 FFI attach_method arg order

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D469019a435a5dbd5c792016fdf67a0b?d=identicon&s=25 Jon Forums (jonm)
on 2008-11-17 17:33
(Received via mailing list)
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-a... 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
5993756d2b69ce0bc16df3318c240d54?d=identicon&s=25 Wayne Meissner (Guest)
on 2008-11-19 01:17
(Received via mailing list)
2008/11/18 Jon <jon.forums@gmail.com>:

> 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
D469019a435a5dbd5c792016fdf67a0b?d=identicon&s=25 Jon Forums (jonm)
on 2008-11-19 14:49
(Received via mailing list)
> > 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
This topic is locked and can not be replied to.