Here's an example how I got mine to work.
How I create my context.
Handle<Context> ScriptManager::createGlobalContext(Isolate* isolate)
{
Handle<ObjectTemplate> global = ObjectTemplate::New();
setGlobalTemplate(isolate, global);
return Context::New(isolate, NULL, global);
}
And that's stored in a persistent for later.
Here's the setGlobalTemplate thing
void ScriptManager::setGlobalTemplate(Isolate* iso, Handle<ObjectTemplate>
tmpl)
{
tmpl->Set(String::New("trace"),
FunctionTemplate::New(UtilityWrapper::Trace), ReadOnly);
tmpl->Set(String::New("randomFloat"),
FunctionTemplate::New(UtilityWrapper::RandomFloat), ReadOnly);
tmpl->Set(String::New("randomInteger"),
FunctionTemplate::New(UtilityWrapper::RandomInteger), ReadOnly);
tmpl->Set(String::New("clamp"),
FunctionTemplate::New(UtilityWrapper::Clamp), ReadOnly);
tmpl->Set(String::New("include"),
FunctionTemplate::New(ScriptManager::Include), ReadOnly);
}
Then of course, to Execute.
Handle<Context> ctx = Local<Context>::New(mGlobalIsolate, mGlobalContext);
ctx->Enter();
Handle<Object> global = ctx->Global();
Local<Script> script = Script::Compile(String::New(fileData->c_str()));
TryCatch tCatch;
Local<Value> result = script->Run();
if(tCatch.HasCaught())
{
String::AsciiValue excep(tCatch.Exception()->ToString());
Utility::trace("Exception Caught in Javascript: " + std::string(*excep));
}
ctx->Exit();
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.