Hi :
Is therer sample code ??
i want to create addon .
The addon object can emit to javascript function
like that
_mNode.on('connected', function(code, descString) {
console.log('Connected to host: '+code+" Desc: "+descString);
});
Can you help me?
SteveCronin於 2011年10月17日星期一UTC+8上午11時21分44秒寫道:
>
> Node 0.5.4 as installed by nodejsmacosx package (Mac OS X 10.6.8)
>
> C++ example usage:
> int FireConnected(EventParams *e) {
> printf("\nc++ - FireConnected");
> Handle<Value> argv[3] = { sym_connectedEvent,
> Integer::New(e->StatusCode),
> String::New(e->Description)
> };
> this->nodeEmitter->Emit(3, argv);
> return 0;
> }
>
> void Emit(int argc, Handle<Value> argv[]) {
> HandleScope scope;
> char emitType[256];
> argv[0]->ToString()->WriteAscii(emitType,0,-1);
> if (showDebugMessages==1) printf("\nEmit - EmitType: %s",
> emitType);
>
> // Paradigm1
> // Local<Function> emit = Local<Function>::Cast(handle_-
> >Get(sym_emit));
> // emit->Call(handle_, argc, argv);
>
> //Paradigm2
> // node::MakeCallback(handle_,"emit",argc,argv);
>
> //Paradigm3
> // Local<String> emit_symbol = String::NewSymbol("emit");
> // Local<Function> emit = obj->Get(emit_symbol).As<Function>(); //
> BenN example code but 'obj' not defined so tried line below
> // Local<Function> emit = Local<Function>::Cast(handle_-
> >Get(emit_symbol));
> // TryCatch tc;
> // emit->Call(Context::GetCurrent()->Global(), argc, argv);
> // if (tc.HasCaught()) {
> // printf("\nnode-motive-xmpps.node - FATAL ERROR");
> // FatalException(tc);
> // }
>
> //Paradigm 4
> // Local<Value> emit_v = handle_->Get(sym_emit);
> // if (!emit_v->IsFunction()) {
> // printf("\nnode-motive-xmpps.node - Not a Function");
> // return;
> // }
> // Local<Function> emit = Local<Function>::Cast(emit_v);
> // TryCatch tc;
> // emit->Call(handle_, argc, argv);
> // if (tc.HasCaught()) {
> // printf("\nnode-motive-xmpps.node - FATAL ERROR");
> // FatalException(tc);
> // }
> }
>
>
> All 4 result in exactly the same Console log:
> ...
> c++ - FireConnected
> Emit - EmitType: connected (then nothing more)
>
>
> --JS test file--
> var XYZ = require('./lib/new-node'); // this is the .js file
> var _mNode = new XYZ;
> _mNode.setServer("blahblah"); //appropriate
> messages in console
> _mNode.makeLongConnection("foo","bar"); //appropriate messages in
> console up to the 'connected' event shown below which never appears
>
> _mNode.on('connected', function(code, descString) {
> console.log('Connected to host: '+code+" Desc: "+descString);
> });
>
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en