I want to call a method written in C++ from a Javascript code passing a string argument. The solution I find is to use Node.js and SWIG to generate bindings.
I followed the example from here (see enobayram post): How can I use a C++ library from node.js?
The C++ method looks like:
Handle<Value> CMyClass::Open(const v8::Arguments& args)
{
HandleScope scope;
std::string port(*v8::String::Utf8Value(args[0]));
std::cout << port << std::endl;
return scope.Close(Undefined());
}
From Node.js console:
var toto = require("./build/Release/MyClass")
var c = new toto.CMyClass()
c.Open("test")
Error: in method 'CMyClass_Open', argument 2 of type 'v8::Arguments const &'
at repl:1:4
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.EventEmitter.emit (events.js:98:17)
at emitKey (readline.js:1095:12)
Any ideas ? Thanks a lot