Hi everyone!  I haven't been using v8 for very long, so please forgive
me if I ask a stupid question... =(

Anyway, I was playing around with v8, and I noticed that there wasn't
a way to "import", so to speak, other Javascript files (within
Javascript) into the main one that the C++ program compiles and runs.
Searching online wasn't much of a help, since almost all of the ways I
found involved web-specific techniques (eg. document.write(...)).

I wrote a small function that _seems_ to work, but I'm not sure if I'm
doing things correctly/efficiently...

v8::Handle<v8::Value> Include(const v8::Arguments& args)
{
v8::HandleScope handle_scope;
v8::Handle<v8::String> jsfile = ReadFile(*v8::String::Utf8Value(args
[0]));  //ReadFile is from shell.cc
v8::Handle<v8::Script> script = v8::Script::Compile(jsfile);
script->Run();
return v8::Undefined();
}

Is there a better way to import/include a Javascript file into
another?

And secondly, I was thinking about having the function return all of
the file's functions, variables, etc., as an object, for a namespace-
esque effect...

eg.
include("test.js");
test.func1();

...but I'm not entirely sure how to go about doing that.

Has anyone else dealt with this issue?  Any solutions would be welcome
=).


Cheers,
~Dennis
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to