How I do it in my game, mind you I can't show everything as its under a NDA.
tmpl->SetAccessor(String::New("ScriptManager"), ScriptManager::GetGlobal);
(Tmpl is the global template)
And GetGlobal is
void ScriptManager::GetGlobal(Local<String> property, const
PropertyCallbackInfo<Value>& info)
{
HandleScope scope(info.GetIsolate());
if(jsGlobal.IsEmpty())
{
Handle<FunctionTemplate> tmpl = FunctionTemplate::New();
tmpl->SetClassName(String::New("ScriptManager"));
Handle<ObjectTemplate> protoTmpl = tmpl->PrototypeTemplate();
protoTmpl->Set(String::New("registerMission"),
FunctionTemplate::New(ScriptManager::RegisterMission));
protoTmpl->Set(String::New("toString"),
FunctionTemplate::New(ScriptManager::ToString));
Handle<Function> ctorFunction = tmpl->GetFunction();
Handle<Object> result = ctorFunction->NewInstance();
BindEnumerations(result);
jsGlobal.Reset(info.GetIsolate(), result);
}
info.GetReturnValue().Set(jsGlobal);
}
So its pretty much just a hidden class that can never be instantiated more
then once, with functions and variables on it.
--
--
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/d/optout.