Subject:
Re: [ruby-ffi] FFI from C?
From:
Wayne Meissner
Date:
4/5/10 3:10 AM
To:
ruby-ffi@googlegroups.com

Short answer is 'no' - there is no C api for Ruby-FFI.

However, can you drive the integration from the ruby side, ala the lua
bindings (http://github.com/jmettraux/rufus-lua)?

I had a quick search for calling Haskell from C, and it looks like it
might be doable - if its callable from straight C, then you can call
it via FFI.

Basically how it would go is:

1) create ruby wrapper method
2) massage ruby data into basic C types (int, string, struct, raw
chunk of memory, etc)
3) call C method exported by Haskell with massaged parameters
4) convert Haskell result back into ruby type.

Calling back into ruby from Haskell via a C function pointer works
similarly, but in reverse.

There was an example on stackoverflow using DL to do this - FFI would
work much the same.

If you're doing it the other way round, calling ruby from Haskell,
you're doomed.  There is no common C api, and no C api at all on JRuby
or IronRuby.


On 5 April 2010 09:03, Mark  Wotton <mwotton@gmail.com> wrote:
> I know this is not the standard method of using the FFI, but is it
> possible to do everything from C? I'm the author of Hubris, a bridge
> between Haskell and Ruby, and because I have way more type information
> on the Haskell side, I'd much rather keep computation on that side,
> which means accessing the FFI from the C side. I'm currently using
> libruby, and it's pretty painful - there's a lot of work to support
> 1.8 and 1.9, and I haven't even considered what it'd take to support
> JRuby yet.
>
> so, to recap: I need a way to reach into the ruby interpreter and get
> type info, as well as access to basic data (numbers, strings, arrays
> and hashes is probably sufficient for now). Is ruby-FFI a good bet?
>
> cheers
> Mark
>
>
> --
> To unsubscribe, reply using "remove me" as the subject.
>