GeezerVison is showing github.com — FFI
Andy Arvanitis edited this page
Jul 26, 2019
·
3 revisions
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 ) and FOREIGN_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<string>(s1) + unbox<string>(s2);
};
};
FOREIGN_END
-
See the standard library implementations for more examples