On Tue, Jun 19, 2012 at 8:27 AM, sahal <[email protected]> wrote: > I'm wrapping a module into an addon. I want to run a standard nodejs script > when the module gets initialized, so that I only have to do "node mymodule" > from the command line. As far as I can see none of the usual module apis are > exposed. How can I do it then? Here's what I've tried: > >> >> #include <node.h> >> >> #include <v8.h> >> >> >> using namespace v8; >> >> >> >> void init(Handle<Object> target) { >> >> Script::New(String::New( " console.log(typeof(require)); "))->Run(); >> // typeof(required)==='undefined' >> >> Script::Compile(String::New( " console.log(typeof(require)); >> "))->Run(); // typeof(required) is also 'undefined' >> >> } >> >> >> NODE_MODULE(mymodule, init)
That doesn't work (and never will). Read src/node.js[1] and lib/module.js[2] to understand why. You normally approach this the other way around, with a javascript shim that sets up whatever it needs to and then loads the native add-on. [1] https://github.com/joyent/node/blob/master/src/node.js [2] https://github.com/joyent/node/blob/master/lib/module.js -- 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
