Take a look at SilkJS. It wraps v8 in C++, and provides both include() and require() methods. You're describing require(), which only loads the library once, but returns the module or namespace for it as many times as you import/require it.
http://github.com/mschwartz/SilkJS And commons.org for docs on require() Sent from my iPhone On Feb 1, 2012, at 2:50 PM, Cédric Tabin <[email protected]> wrote: > Hello, > > I'm a new user of the V8 framework and try to play with it :-) > Currently, I'd like to handle a library (in javascript) that will be > used by other scripts, all run by the V8's engine. For example I will > have something like that: > > == library.js == > function doSomething() { print "library"; } > > == script1.js == > /* import/include library.js */ > function doSomething() { print "script1"; } //override the doSomething > method from library.js > doSomething(); //should return *script1* > > == script2.js == > /* import/include library.js */ > doSomething(); //should return *library* > > > My goal is to avoid reexecuting the whole file library.js before > running script1.js or script2.js. In my C++ code, I'd like to do > something like that: > a) prepare environment (Context, Scope, ...) > b) compile & execute library.js > c) take a "snapshot" of the current state (or something like that) > d) compile & execute script1.js > e) reset the state in (c) > f) compile & execute script2.js (so it runs like if script1.js was > never ran, withou re-running library.js) > > I had a look to the Contexts, but it is to run for independant code > which is clearly not my case... I also tried to play with Scope and > HandleScope with no result. > > Is there a way to handle this problem ? > > Thanks & best regards, > Cedric > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
