node.js addon - how to pass a string parameter to (nan) C++ -
my node.js code :
var mymq = require( './build/release/mqconn' ) ; var myqmgrname = 'qm_cnt' ; // req.params.qmgrname ; mymq.connect ( myqmgrname, function ( err, result ) {
and c++ code (uning nan) wants receive first string parameter :
nan_method( mq_connect ) { nanscope(); local<value> szqmn( args[ 0 ] ); printf( "(cc)>>>> qmn [%s].\n", szqmn ) ;
... garbage.
any clue on doing wrong ? sebastian.
first should validate arguments. can string calling tostring()
on argument. example:
nan_method(mq_connect) { nanscope(); if (args.length() > 0) { if (args[0]->isstring()) { string::utf8value str(args[0]->tostring()); printf("(cc)>>>> qmn [%s].\n", (const char*)(*str)); } }
Comments
Post a Comment