FFI (original) (raw)
C++11 target foreign exports
- Foreign values are resolved dynamically/lazily (and "cached" thereafter), so you don't need to define all of them right away. If needed and missing during runtime, an exception will be thrown. Using a source-level debugger which supports C++ will reveal the missing implementation easily enough.
- To implement foreign values to be exported:
- Create a C++ source file (typically in
your_workspace/ffi
) - #include
purescript.h
and any other C/C++ dependencies - Use macros
FOREIGN_BEGIN( Module_Name )
andFOREIGN_END
to delineate your block of exported values.
For example:
#include "purescript.h"
// Tested with package v4.0.0
FOREIGN_BEGIN( Data_Semigroup )
exports["concatString"] = [](const boxed& s1) -> boxed {
return [=](const boxed& s2) -> boxed {
return unbox(s1) + unbox(s2);
};
};
FOREIGN_END - Create a C++ source file (typically in
- See the standard library implementations for more examples