nbind icon indicating copy to clipboard operation
nbind copied to clipboard

string references support in nbind

Open iasna opened this issue 7 years ago • 3 comments

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.

iasna avatar Mar 01 '18 12:03 iasna

Uhm, if you are expecting the two vars to be set by the function, you're doing it wrong: js cannot do that.

parro-it avatar Mar 01 '18 15:03 parro-it

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.

iasna avatar Mar 02 '18 06:03 iasna

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);

nbeerbower avatar Mar 05 '18 19:03 nbeerbower