deech / fltkhs

Haskell bindings to FLTK GUI toolkit.
MIT License
190 stars 24 forks source link

Support for fl_open_callback on Mac #137

Closed mtolly closed 5 years ago

mtolly commented 5 years ago

I'd like to use fl_open_callback in the Mac version of an app I'm working on to accept files dropped on the dock icon. I didn't see a binding for it, so I tried doing one myself:

type OpenCallback = CString -> IO ()
foreign import ccall unsafe "fl_open_callback"
  fl_open_callback :: FunPtr OpenCallback -> IO ()
foreign import ccall "wrapper"
  mkOpenCallback :: OpenCallback -> IO (FunPtr OpenCallback)

I'm using the bundled version of FLTK, and the function appears to be missing:

Undefined symbols for architecture x86_64:
  "_fl_open_callback", referenced from:
      _c2ezs_info in FLTK.o
ld: symbol(s) not found for architecture x86_64

I haven't yet tried using a separately installed version of FLTK to see if it is there.

deech commented 5 years ago

x.H is an alias for platform.H so try using that header instead. Hmm, it looks like I only bound 2 of the functions in that file, possibly because I was trying to stay away from platform specific functions.

deech commented 5 years ago

Although I don't remember doing it, I wrote C bindings for a few more of them. If you want to add to that instead and submit a PR that's fine too. But I don't know how to "cross-generate" Haddocks. Now that I think about it that maybe why I didn't bind those in the first place. If you have any ideas, let me know.

mtolly commented 5 years ago

Ahh, I was under the mistaken impression that it was already a C-compatible symbol since it was a simple global function and not a class method, but I see it is still C++ and needs a wrapper. I will see if I can add that when I have the chance :)

As for the platform specificness, if I'm understanding the docs and source correctly, the function exists on all platforms; the callback just never gets called on non-Mac platforms. So it should be fine to bind to it (and include it in docs) on all platforms, I think.