C++ addon running differently in Linux and Windows

21 views
Skip to first unread message

dod...@gmail.com

unread,
Apr 22, 2015, 10:49:56 PM4/22/15
to nod...@googlegroups.com
I just started learning node.js and C++ addon. I modified the hello world example a little bit to see how it works. Then I found out it runs differently in Linux and Windows.

Basically, I added an internal function that used cout to output to the console. I know this is not a good practice for the purpose of NW but I just wanted to test how it handles these situations. In Linux, the output is

worldtest
yes

but in Windows, it is

yes
worldtest

it seems the Windows output is what I expected it to be. Any ideas what I'm missing here?  Thanks!

#include <node.h>
#include <v8.h>
#include <string>
#include <iostream>


using namespace v8;
using namespace std;
string changestring(string tmp);

void Method(const v8::FunctionCallbackInfo<Value>& args) {
 
Isolate* isolate = Isolate::GetCurrent();
 
HandleScope scope(isolate);
 
string tmp=changestring("world");
 
const char * c=tmp.c_str();
  args
.GetReturnValue().Set(String::NewFromUtf8(isolate, c));

 
}

void Init(Handle<Object> exports) {
 
Isolate* isolate = Isolate::GetCurrent();
  exports
->Set(String::NewFromUtf8(isolate, "hello"),
     
FunctionTemplate::New(isolate, Method)->GetFunction());
}

string changestring(string tmp)
{
    cout
<<"yes\n";
   
return (tmp+"test\n");
   
}

NODE_MODULE
(hello, Init)

Reply all
Reply to author
Forward
0 new messages