my question begins after running $ nodejs myapp.js somearg
, a node c++ addon is loaded with require()
, then:
Is possible to get the command line arguments also from c++ addon code?
From the file with javascript code using http://ift.tt/2uXSdrj is possible to read the commandline argc/argv of the current running app, but im not able to find a way to get the argc/argv within a method of a node c++ addon.
i think i should use node::Environment
class, but i can't find how to use it :( and im starting to be totally lost, please enlightenme in some direction
as a example code im trying to make the Method
method of the the basic hello world example to return the first argument somearg
instead of "world", but i had no luck after many effort
#include <node.h>
#include <v8.h>
using namespace v8;
void Method(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}
void Init(Handle<Object> exports) {
Isolate* isolate = Isolate::GetCurrent();
exports->Set(String::NewFromUtf8(isolate, "hello"),
FunctionTemplate::New(isolate, Method)->GetFunction());
}
NODE_MODULE(hello, Init)
many thanks for your time''
Aucun commentaire:
Enregistrer un commentaire