Hi,
I am new both to V8 and C++. So, I'm afraid I am
going to ask something very obvious. Please don't
flame me too much!
What I am trying to do is:
1) create some c++ functions callable from JS in the main, like:
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
v8::Handle<v8::Context> context = v8::Context::New(NULL, global);
v8::Context::Scope context_scope(context);
global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print));
2) Run JS, like:
v8::HandleScope handle_scope;
v8::Handle<v8::Script> script = v8::Script::Compile(source, name);
v8::Handle<v8::Value> result = script->Run();
3) From JS I wil call a C++ function "create" that will create new C++ functions
callable from JS, like "newfn". And that's the point I am stuck: when I call
"create" I do this:
global->Set(v8::String::New("newfn"), v8::FunctionTemplate::New(Newfn));
but, after "create" returns to JS, I try to call newfn and I get
an error message:
"test.js:3: ReferenceError: newfn is not defined"
I believe that this happens why when I compile and run, I do it in a
separate scope
than the scope in "create". But I tried to make "global" a global
variable, I tried to
make Persistent context, etc, etc. But nothing worked. Is it possible
(and how to
do it) to create new objects in the context of a running script from a
C++ function?
Thank you in advance,
--
Luis Otavio de Colla Furquim
Não alimente os pingos
Don't feed the tribbles - http://www.thinkgeek.com/geektoys/plush/ac6e/
By the nice edges of dataly graphs I shall walk
http://www.furquim.org/chironfs/
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---