nbind
nbind copied to clipboard
string references support in nbind
This issue has been reported previously here https://github.com/charto/nbind/issues/69, but was closed, but still I'm unable to call C++ methods that have string references as parameter, below is my method signature
void getCodeFromSymbol(const std::string& symbol, std::string& code);
this is how I have exposed it
method(getCodeFromSymbol);
calling from js here :
var code;
var symbol;
obj.getCodeFromSymbol(code, symbol);
giving me
TypeError: Type mismatch.
Uhm, if you are expecting the two vars to be set by the function, you're doing it wrong: js cannot do that.
after reading this https://github.com/charto/nbind#using-objects setting Javascript var in c++ seemed possible, but there are ways present if I use v8 classes directly.
Yes it seems you can pass objects by reference but it's not recommend.
It looks like you're not initializing code or symbol so they're not of type string and would therefore give you a type mismatch error. See here for the JS/C++ type conversions.
Try:
var code = '';
var symbol = '';
obj.getCodeFromSymbol(code, symbol);