I am trying to port the haskell minisat library to JavaScript using ghcjs to integrate into the larger haskell-ghcjs project.
minisat contains a pair of imported ffi from c library. I managed to compile the javascript c library using emscripten and export the functions that minisat required. So far so good.
However, there are several imported goods that look like this:
foreign import ccall safe minisat_solve :: Solver -> Int -> Ptr (Lit) -> IO (Bool)
which imports a function that looks like this:
int minisat_solve(minisat_solver *s, int len, minisat_Lit *ps)
My understanding, from the documentation , is that when emscripten exports a function that accepts or returns a pointer, the pointer becomes the JavaScript type number.
The ghcjs documentation assumes that you can leave the existing import import by properly wrapping the JavaScript function. However, ghcjs presents pointer types as roughly a pair consisting of an object and a JavaScript number.
I think the shell code should be approximately
function h$minisat_solve(...){
...
minisat_solve(...)
...
}
function minisat_solve = Module.cwrap('minisat_solve',...,...)
But I'm not happy with the type mismatch.
So, here's the challenge: Explain how to properly wrap the emscripten export for import ccall
by ghcjs
using the wrapper code above as an example (or a counterexample if I'm completely mistaken)