You can define your own C functions for highlighting, freeing, pasting, deleting, etc. These functions can wrap the C ++ container that you want to access. For example:
extern "C" { Obj * obj_create() { return new Obj(); } void obj_destroy(Obj * schema) { delete obj; obj = NULL; } ... ... }
then declare them in FFI and wrap them in whatever way you want.
data SomeObject type Obj = Ptr SomeObject foreign import ccall unsafe "obj_create" createObj :: IO Obj foreign import ccall unsafe "obj_destroy" destroyObj_ :: Obj -> IO () foreign import ccall unsafe "&obj_destroy" destroyObj :: FunPtr (Obj -> IO ())
Some Gotchas:
- Make sure you compile C files using the C ++ compiler (g ++ instead of gcc). this ensures that stdC ++ files are loaded correctly.
- Pass the library addresses (-L) and libs (-lboost *) for reference when compiling the / lib program on the haskell side
Chetan
source share