[Haskell-cafe] FFI woes!
Sebastian Sylvan
sebastian.sylvan at gmail.com
Wed Dec 15 07:13:19 EST 2004
On Wed, 15 Dec 2004 06:04:37 -0500, David Roundy
<droundy at abridgegame.org> wrote:
> On Wed, Dec 15, 2004 at 04:09:04AM +0100, Sebastian Sylvan wrote:
> > FMUSIC_MODULE * F_API FMUSIC_LoadSong(
> > const char *name
> > );
> >
> > By doing this in Haskell:
> >
> > data MusicModule = MusicModule
> >
> > foreign import ccall "fmod.h FMUSIC_LoadSong" fmusic_LoadSong ::
> > CString -> IO ForeignPtr MusicModule)
> >
> > I assume that this is how the ForeignPtr is meant to be used (with a
> > dummy data type).
>
> No, a ForeignPtr is a purely haskell object. The C function returns a
> Ptr. You could create a ForeignPtr from the Ptr if you want it to be
> automatically freed (calling somesort of FreeSong, presumably) when it gets
> garbage collected.
Ah. Thanks.
Another problem!
When a handle is not being referenced I don't want it to be garbage
collected if the isPlaying function returns True (in other words I
want the song to finish playing even if it's not being referenced
anymore).
The current plan of attack is to have the finalizer fork off a thread
which does nothing but check the status of the song every 500ms or so
and when it's finished, releases it. But since I really only need to
check it every time the garbage collector wants to release it maybe
there's a better way?
So I want to annotate the ForeignPtr with a function which can defer
it's release based on the status of the handle. Is there a way to do
this?
Sadly the C library doesn't seem to provide a callback for when the
song has finished playing which would be ideal.
/S
--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
More information about the Haskell-Cafe
mailing list