需求:是有个C++接口,参数是vector<string>类型,那么如何在js端调用这个接口呢?
#include <emscripten/emscripten.h>
#include <emscripten/bind.h>
#include <vector>
#include <string>
#include <iostream>
using namespace emscripten;
using namespace std;
void testVector(const vector<string> vct)
{
for(auto it:vct)
std::cout << it <<std::endl;
}
EMSCRIPTEN_BINDINGS(vector_example) {
emscripten::function("testVector", &testVector);
register_vector<string>("StringList");
}
调用
const families = new Module.StringList();
families.push_back("微软雅黑");
families.push_back("宋体");
families.push_back("楷体");
families.push_back("黑体");
families.push_back("幼圆");
families.push_back("华文琥珀");
families.push_back("华文彩云");
families.push_back("华文行楷");
families.push_back("华文细黑");
families.push_back("华文仿宋");
families.push_back("华文楷体");
families.push_back("Calibri");
families.push_back("Arial");
Module.testVector(families);
结果: