// A C++ library that will
// be used across languages
#include <string>
namespace Hello {
std::string cppFunction(std::string const &name) {
return "Hello " + name + "!\n";
}
}
// Bindings generated by Tolc
#include <MyCppLib.hpp>
#include <pybind11/pybind11.h>
namespace py = pybind11;
PYBIND11_MODULE(MyCppLib, MyCppLib) {
auto MyCppLib_Hello = MyCppLib.def_submodule("Hello");
MyCppLib_Hello.def("cppFunction", &Hello::cppFunction, "", py::arg("name"));
}
#include </home/simon/code/elixir/tolc_main/example/tolc-live/build/tolc/tolc_MyCppLib.hpp>
#include <emscripten/bind.h>
namespace em = emscripten;
EMSCRIPTEN_BINDINGS(MyCppLib) {
em::function("Hello_cppFunction", &Hello::cppFunction);
}
# A python file that
# uses the C++ library MyCppLib
import MyCppLib
print(MyCppLib.Hello.cppFunction("friend"))
// A javascript file that
// uses the C++ library MyCppLib
const loadMyCppLib = require('./MyCppLib');
// WebAssembly is loaded asynchronous
// via a Promise
loadMyCppLib().then(MyCppLib => {
console.log(MyCppLib.Hello.cppFunction('friend'));
});