I'm trying to port the haskell library minisat to JavaScript using ghcjs, for integration in a larger haskell-ghcjs project.
minisat contains a couple of ffi imports from a c library. I've manged to compile the c library to javascript using emscripten, and to export the functions that minisat requires. So far, so good.
However, there are a couple of imports 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 takes or returns a pointer, the pointer becomes a JavaScript number type.
The ghcjs documentation suggests that it should be possible to leave the existing foreign imports in place, by appropriately wrapping a JavaScript function. However, ghcjs represents pointer types as roughly a pair consisting of a JavaScript object and number.
I think the wrapper code should be roughly
function h$minisat_solve(...){
...
minisat_solve(...)
...
}
function minisat_solve = Module.cwrap('minisat_solve',...,...)
But I'm stumped by the type mismatch.
So, here's the challenge: Explain how to properly wrap an emscripten export for ccall
import by ghcjs
, using the above wrapper code as an example (or a counterexample, if I've got it completely wrong)