Subject:
Re: [ruby-ffi] I wrote on advanced FFI usage
From:
Kim Burgestrand
Date:
3/30/13 4:19 PM
To:
ruby-ffi@googlegroups.com

wayne: (so now I know the story behind all those issues you raised against JRuby)
Hehe, yes. I wanted to see if I could run some MRI-working code (spotify gem + OpenAL) on JRuby,
and in doing that I ran into a few issues. The reason for doing that was because I became curious as
I was writing the article. I’m happy to say I managed to get it running on JRuby, streaming music from
the spotify API, bound with FFI, into the OpenAL API, bound with FFI. Really cool!
postmodern: all of the other blog posts only cover loading a library and attaching some functions.
Yes. I have not yet found a blog post that explains the basics better than the wiki though. The wiki is
a nice collection of information, and it was pretty much my bible when I started with FFI, together with
the FFI source code. I believe there is place for yet another article on FFI, aimed at people beginning
with FFI for the first time.
wayne: Any subclass of FFI::AutoPointer can be used as a function result, and it automatically wraps the result of the function in that AutoPointer subclass.
This is a really nice way of using FFI, and I actually do this throughout all one of my FFI gems. The
spotify library in particular uses a reference counting mechanism, where some functions return pointers
that should have their reference increased, and I do that automatically with a similar mechanic to .auto_ptr:
https://github.com/Burgestrand/spotify/blob/a7deb7b4e9334c95f6c3a2d8f077264dc7d55f8d/lib/spotify/managed_pointer.rb#L76
4) Completely replace the FFI api with your own concoction.  Using FFI::DynamicLibrary, FFI::Function, and FFI::DataConverter, you can write your own API for mapping C libraries into ruby.  Thats how JRuby implements legacy interfaces like dl and Win32API.
I did not know you could do that. Nice!

— Kim

--
 
---
You received this message because you are subscribed to the Google Groups "ruby-ffi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-ffi+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.