I think the point is using package.json to define the module entry by an js file that wrap your addon.
2012/6/20 sahal <[email protected]> > > Ok so instead of running "node.exe mymodule.node" I need to run "node.exe > -e require('mymodule.node').start(module); " > And in mymodule.cc write a function start() which compiles and runs a > v8::Function, > passing it args[0] and work with it like with(arguments[0]) { > console.log(require); } > > This works, but the question is, will this be stable between releases? > > > On Wednesday, June 20, 2012 12:02:15 AM UTC+3, Nathan Rajlich wrote: > >> No, that's not what he's saying. >> >> Basically, instead of having the .node file be the "entry point" to your >> module, have a separate .js file that will act as the entry point, that >> also does other initialization like requiring your own native bindings. >> Then in your package.json file, the "main" field points to this .js file >> rather than the .node file. >> >> See ref's main .js file for an example: >> https://github.com/TooTallNate/ref/blob/master/lib/ref.js >> >> On Tue, Jun 19, 2012 at 12:30 PM, sahal <> wrote: >> >>> On Tuesday, June 19, 2012 3:04:00 PM UTC+3, Ben Noordhuis wrote: >>> >>>> On Tue, Jun 19, 2012 at 8:27 AM, sahal <> 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 >>> >>> >>> >>> So you're basically telling me that I need to pass the contents of >>> process.execPath back to my addon, use CreateProcess and pass the script as >>> --eval command line argument? >>> >>> >>> >>> -- >>> 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 >>> >> >> -- > 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 > -- AUFKLÄRUNG ist der Ausgang des Menschen aus seiner selbstverschuldeten Unmündigkeit. Unmündigkeit ist das Unvermögen, sich seines Verstandes ohne Leitung eines anderen zu bedienen. Selbstverschuldet ist diese Unmündigkeit, wenn die Ursache derselben nicht am Mangel des Verstandes, sondern der Entschließung und des Mutes liegt, sich seiner ohne Leitung eines andern zu bedienen. Sapere aude! Habe Mut, dich deines eigenen Verstandes zu bedienen! ist also der Wahlspruch der Aufklärung. -- 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
