问题
I use swig to write NodeJS's addon and encountered an error.
is it support std::vector* as a OUTPUT?
my *.i:%apply std::vector<std::string> *OUTPUT {std::vector<std::string>* result};
when I run swig:swig -javascript -node -c++ -DV8_VERSION=0x040599 export.i
has error:export.i:19: Warning 453: Can't apply (std::vector< std::string > *OUTPUT). No typemaps are defined.
I encountered an error at swig-javascript, but it works fine at swig-python.
Anyone can help?
thanks
回答1:
Adding:
%include "std_string.i"
%include "std_vector.i"
namespace std {
%template(StringVector) vector<string>;
}
early in your file seems to be enough to make it work, eg. for a C++ class
class MyClass {
public:
std::vector<std::string> getNames();
(...)
the following code will work on the Javascript side:
var o = ...
a = o.getNames();
console.log("size: " + a.size());
for (i = 0; i < a.size(); i++) {
console.log(a.get(i));
}
This is for SWIG 3, and it works as documented in http://www.swig.org/Doc1.3/Library.html#Library_nn15
来源:https://stackoverflow.com/questions/34739912/swig-javascriptis-it-support-stdvectorstdstring-as-a-output