调试学习wasm,emscripten的各种用法 js 与 C++ 的交互
1.下载 emsdk
2.安装 emsdk
3.创建cpp文件 比如说 main.cpp
4.使用embind 导出函数 导出类 导出vector 等等
示例代码如下:
#include <emscripten.h>
#include <emscripten/bind.h>
#include <string>
#include <vector>
using namespace emscripten;
// This is your routine C++ code
size_t MyStrLen(std::string inStr) {
return inStr.length();
}
std::string MyStr(std::string inStr) {
string str = inStr + "123";
return str;
}
// This is the extra code you need to write to expose your function to JS
EMSCRIPTEN_BINDINGS(my_module) {
emscripten::function("MyStrLen", &MyStrLen);
}
EMSCRIPTEN_BINDINGS(my_module_1) {
emscripten::function("MyStr", &MyStr);
}
//Embind classes
class MyCl