本文整理汇总了C++中Handle::PrototypeTemplate方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::PrototypeTemplate方法的具体用法?C++ Handle::PrototypeTemplate怎么用?C++ Handle::PrototypeTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Handle
的用法示例。
在下文中一共展示了Handle::PrototypeTemplate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateDebugDrawManager
v8::Handle<v8::Function> CreateDebugDrawManager(Handle<Context> context)
{
v8::HandleScope handle_scope;
Handle<FunctionTemplate> templt = GetScriptSystem()->GetTemplateBySID(s_debugDrawWrapper);
if(templt.IsEmpty())
{
templt = FunctionTemplate::New();
templt->SetClassName(String::New("DebugDrawManager"));
templt->InstanceTemplate()->SetInternalFieldCount(1);
Handle<ObjectTemplate> proto = templt->PrototypeTemplate();
proto->Set("addAABB", FunctionTemplate::New(DebugDrawManagerAddAABB));
proto->Set("addCircle", FunctionTemplate::New(DebugDrawManagerAddCircle));
proto->Set("addCross", FunctionTemplate::New(DebugDrawManagerAddCross));
proto->Set("addLine", FunctionTemplate::New(DebugDrawManagerAddLine));
proto->Set("addLines", FunctionTemplate::New(DebugDrawManagerAddLines));
proto->Set("addSphere", FunctionTemplate::New(DebugDrawManagerAddSphere));
proto->Set("addString", FunctionTemplate::New(DebugDrawManagerAddString));
proto->Set("addTriangle", FunctionTemplate::New(DebugDrawManagerAddTriangle));
proto->Set("clear", FunctionTemplate::New(DebugDrawManagerClear));
proto->Set("isEnabled", FunctionTemplate::New(DebugDrawManagerIsEnabled));
proto->Set("setEnabled", FunctionTemplate::New(DebugDrawManagerSetEnabled));
proto->Set("toString", FunctionTemplate::New(DebugDrawManagerToString));
GetScriptSystem()->SetTemplateBySID(s_debugDrawWrapper, templt);
}
return handle_scope.Close(templt->GetFunction());
}
示例2: context_scope
v8::Handle<v8::Object> WrapScreen(ScriptSystem* ss)
{
HandleScope handle_scope;
Handle<Context> context = ss->GetGlobalContext();
Context::Scope context_scope(context);
Handle<FunctionTemplate> templt = FunctionTemplate::New();
templt->SetClassName(String::New("Screen"));
Handle<ObjectTemplate> proto = templt->PrototypeTemplate();
proto->Set("toString", FunctionTemplate::New(SCRToString));
proto->Set("getPickRay", FunctionTemplate::New(SCRGetPickRay));
proto->Set("intersect", FunctionTemplate::New(SCRIntersect));
proto->Set("pickEntity", FunctionTemplate::New(SCRPickEntity));
proto->Set("convertWorldToScreenCoords", FunctionTemplate::New(SCRConvertWorldToScreenCoords));
proto->Set("openWindow", FunctionTemplate::New(SCROpenWindow));
proto->Set("closeWindow", FunctionTemplate::New(SCRCloseWindow));
proto->Set("getWindowGeometry", FunctionTemplate::New(SCRGetWindowGeometry));
proto->Set("setWindowGeometry", FunctionTemplate::New(SCRSetWindowGeometry));
Local<Object> instance = templt->GetFunction()->NewInstance();
instance->SetAccessor(String::New("lockCursor"), SCRGetLockCursor, SCRSetLockCursor);
instance->SetAccessor(String::New("showCursor"), SCRGetShowCursor, SCRSetShowCursor);
instance->SetAccessor(String::New("width"), SCRGetWidth);
instance->SetAccessor(String::New("height"), SCRGetHeight);
instance->SetAccessor(String::New("fullScreen"), SCRGetFullScreen, SCRSetFullScreen);
return handle_scope.Close(instance);
}
示例3: New
JsEngine* JsEngine::New(int32_t max_young_space = -1, int32_t max_old_space = -1)
{
JsEngine* engine = new JsEngine();
if (engine != NULL)
{
engine->isolate_ = Isolate::New();
engine->isolate_->Enter();
if (max_young_space > 0 && max_old_space > 0) {
v8::ResourceConstraints constraints;
constraints.set_max_young_space_size(max_young_space * Mega);
constraints.set_max_old_space_size(max_old_space * Mega);
v8::SetResourceConstraints(&constraints);
}
engine->isolate_->Exit();
Locker locker(engine->isolate_);
Isolate::Scope isolate_scope(engine->isolate_);
HandleScope scope;
// Setup the template we'll use for all managed object references.
Handle<FunctionTemplate> fo = FunctionTemplate::New(NULL);
Handle<ObjectTemplate> obj_template = fo->InstanceTemplate();
obj_template->SetInternalFieldCount(1);
obj_template->SetNamedPropertyHandler(
managed_prop_get,
managed_prop_set,
NULL,
managed_prop_delete,
managed_prop_enumerate);
obj_template->SetCallAsFunctionHandler(managed_call);
engine->managed_template_ = new Persistent<FunctionTemplate>(Persistent<FunctionTemplate>::New(fo));
Persistent<FunctionTemplate> fp = Persistent<FunctionTemplate>::New(FunctionTemplate::New(managed_valueof));
engine->valueof_function_template_ = new Persistent<FunctionTemplate>(fp);
engine->global_context_ = new Persistent<Context>(Context::New());
(*engine->global_context_)->Enter();
fo->PrototypeTemplate()->Set(String::New("valueOf"), fp->GetFunction());
(*engine->global_context_)->Exit();
}
return engine;
}
示例4: GetOrCreateInternal
Handle<FunctionTemplate> MetadataNode::GetConstructorFunctionTemplate(Isolate *isolate, MetadataTreeNode *treeNode)
{
SET_PROFILER_FRAME();
Handle<FunctionTemplate> ctorFuncTemplate;
auto itFound = s_ctorFuncCache.find(treeNode);
if (itFound != s_ctorFuncCache.end())
{
ctorFuncTemplate = Local<FunctionTemplate>::New(isolate, *itFound->second);
return ctorFuncTemplate;
}
auto node = GetOrCreateInternal(treeNode);
auto ctorCallbackData = External::New(isolate, node);
auto isInterface = s_metadataReader.IsNodeTypeInterface(treeNode->type);
auto funcCallback = isInterface ? InterfaceConstructorCallback : ClassConstructorCallback;
ctorFuncTemplate = FunctionTemplate::New(isolate, funcCallback, ctorCallbackData);
auto baseClass = s_metadataReader.GetBaseClassNode(treeNode);
Handle<Function> baseCtorFunc;
if ((baseClass != treeNode) && (baseClass != nullptr) && (baseClass->offsetValue > 0))
{
auto baseFuncTemplate = GetConstructorFunctionTemplate(isolate, baseClass);
if (!baseFuncTemplate.IsEmpty())
{
ctorFuncTemplate->Inherit(baseFuncTemplate);
baseCtorFunc = baseFuncTemplate->GetFunction();
}
}
auto prototypeTemplate = ctorFuncTemplate->PrototypeTemplate();
auto ctorFunc = node->SetMembers(isolate, ctorFuncTemplate, prototypeTemplate, treeNode);
if (!baseCtorFunc.IsEmpty())
{
ctorFunc->SetPrototype(baseCtorFunc);
}
auto pft = new Persistent<FunctionTemplate>(isolate, ctorFuncTemplate);
s_ctorFuncCache.insert(make_pair(treeNode, pft));
SetInnnerTypes(isolate, ctorFunc, treeNode);
SetTypeMetadata(isolate, ctorFunc, new TypeMetadata(s_metadataReader.ReadTypeName(treeNode)));
return ctorFuncTemplate;
}
示例5: InitAnimationSystemWrapper
void InitAnimationSystemWrapper(ScriptSystem* ss)
{
HandleScope scope;
Context::Scope context_scope(ss->GetGlobalContext());
Handle<FunctionTemplate> templt = FunctionTemplate::New();
templt->SetClassName(String::New("SoundSystem"));
templt->InstanceTemplate()->SetInternalFieldCount(1);
Handle<ObjectTemplate> proto = templt->PrototypeTemplate();
proto->Set("toString", FunctionTemplate::New(ASToString));
proto->Set("playAnimation", FunctionTemplate::New(ASPlayAnimation));
proto->Set("clearAnimation", FunctionTemplate::New(ASClearAnimation));
proto->Set("hasAnimation", FunctionTemplate::New(ASHasAnimation));
proto->Set("isAnimationPlaying", FunctionTemplate::New(ASIsAnimationPlaying));
proto->Set("clearAll", FunctionTemplate::New(ASClearAll));
proto->Set("getRegisteredAnimations", FunctionTemplate::New(ASGetRegisteredAnimations));
RegisterEntitySystempWrapper(ss, dtEntity::AnimationComponent::TYPE, templt);
}
示例6: WrapLogger
v8::Handle<v8::Object> WrapLogger(Handle<Context> context)
{
v8::HandleScope handle_scope;
Handle<FunctionTemplate> templt = GetScriptSystem()->GetTemplateBySID(s_loggerWrapper);
if(templt.IsEmpty())
{
templt = FunctionTemplate::New();
templt->SetClassName(String::New("Log"));
Handle<ObjectTemplate> proto = templt->PrototypeTemplate();
proto->Set("always", FunctionTemplate::New(LogAlways));
proto->Set("debug", FunctionTemplate::New(LogDebug));
proto->Set("error", FunctionTemplate::New(LogError));
proto->Set("info", FunctionTemplate::New(LogInfo));
proto->Set("warning", FunctionTemplate::New(LogWarning));
proto->Set("addLogListener", FunctionTemplate::New(LogAddListener));
proto->Set("processLogListeners", FunctionTemplate::New(LogProcessListeners));
GetScriptSystem()->SetTemplateBySID(s_loggerWrapper, templt);
}
Local<Object> instance = templt->GetFunction()->NewInstance();
return handle_scope.Close(instance);
}
示例7: WrapElementDocument
v8::Handle<v8::Object> WrapElementDocument(v8::Handle<v8::Context> context, Rocket::Core::ElementDocument* v)
{
v8::HandleScope handle_scope;
Handle<FunctionTemplate> templt = GetScriptSystem()->GetTemplateBySID(s_elementDocumentWrapper);
if(templt.IsEmpty())
{
templt = FunctionTemplate::New();
templt->Inherit(GetElementTemplate());
templt->SetClassName(String::New("ElementDocument"));
templt->InstanceTemplate()->SetInternalFieldCount(1);
templt->InstanceTemplate()->SetNamedPropertyHandler(
ELNamedPropertyGetter,
ELNamedPropertySetter,
ELNamedPropertyQuery,
ELNamedPropertyDeleter,
ELNamedPropertyEnumerator
);
Handle<ObjectTemplate> proto = templt->PrototypeTemplate();
proto->Set("hide", FunctionTemplate::New(EDHide));
proto->Set("toString", FunctionTemplate::New(EDToString));
proto->Set("show", FunctionTemplate::New(EDShow));
proto->Set("hide", FunctionTemplate::New(EDHide));
proto->Set("close", FunctionTemplate::New(EDClose));
GetScriptSystem()->SetTemplateBySID(s_elementDocumentWrapper, templt);
}
Local<Object> instance = templt->GetFunction()->NewInstance();
instance->SetInternalField(0, External::New(v));
return handle_scope.Close(instance);
}
示例8: WrapComponent
Handle<Object> WrapComponent(Handle<Object> wrappedes, ScriptSystem* scriptsys, dtEntity::EntityId eid, dtEntity::Component* v)
{
HandleScope handle_scope;
Handle<Object> wrapped = scriptsys->GetFromComponentMap(v->GetType(), eid);
if(!wrapped.IsEmpty())
{
return wrapped;
}
Handle<FunctionTemplate> templt = GetScriptSystem()->GetTemplateBySID(s_componentWrapper);
if(templt.IsEmpty())
{
templt = FunctionTemplate::New();
templt->SetClassName(String::New("Component"));
templt->InstanceTemplate()->SetInternalFieldCount(1);
Handle<ObjectTemplate> proto = templt->PrototypeTemplate();
proto->Set("equals", FunctionTemplate::New(COEquals));
proto->Set("getType", FunctionTemplate::New(COGetType));
proto->Set("properties", FunctionTemplate::New(COProperties));
proto->Set("toString", FunctionTemplate::New(COToString));
proto->Set("finished", FunctionTemplate::New(COFinished));
proto->Set("copyPropertyValues", FunctionTemplate::New(COCopyPropertyValues));
GetScriptSystem()->SetTemplateBySID(s_componentWrapper, templt);
}
Local<Object> instance = templt->GetFunction()->NewInstance();
instance->SetInternalField(0, External::New(v));
instance->SetHiddenValue(scriptsys->GetEntityIdString(), Uint32::New(eid));
// GetStringFromSID and conversion to v8::String is costly, create a
// hidden value in entity system wrapper that stores
// strings and their string ids as name=>value pairs
Handle<Value> propnamesval = wrappedes->GetHiddenValue(scriptsys->GetPropertyNamesString());
if(propnamesval.IsEmpty())
{
Handle<Object> names = Object::New();
dtEntity::PropertyGroup::const_iterator i;
const dtEntity::PropertyGroup& props = v->Get();
for(i = props.begin(); i != props.end(); ++i)
{
dtEntity::StringId sid = i->first;
std::string propname = dtEntity::GetStringFromSID(sid);
names->Set(String::New(propname.c_str()), WrapSID(sid));
}
wrappedes->SetHiddenValue(scriptsys->GetPropertyNamesString(), names);
propnamesval = names;
}
Handle<Object> propnames = Handle<Object>::Cast(propnamesval);
Handle<Array> keys = propnames->GetPropertyNames();
for(unsigned int i = 0; i < keys->Length(); ++i)
{
Handle<String> str = keys->Get(i)->ToString();
dtEntity::StringId sid = UnwrapSID(propnames->Get(str));
dtEntity::Property* prop = v->Get(sid);
if(prop == NULL)
{
LOG_ERROR("Could not find property in component: " << ToStdString(str));
continue;
}
Handle<External> ext = v8::External::New(static_cast<void*>(prop));
instance->SetAccessor(str, COPropertyGetter, COPropertySetter, ext);
}
// store wrapped component to script system
scriptsys->AddToComponentMap(v->GetType(), eid, instance);
return handle_scope.Close(instance);
}
示例9: context_scope
void CanvasContextV8Bindings::loadScript(const std::string& _filename, OgreCanvas::CanvasContext* _canvasContext, OgreCanvas::CanvasLogger* _console)
{
CanvasContextV8Bindings::context2D = _canvasContext;
HandleScope handle_scope;
//Console :
//template
Handle<FunctionTemplate> consoleTemplate = FunctionTemplate::New();
consoleTemplate->SetClassName(v8::String::New("Console"));
CanvasContextV8Bindings::consoleTemplate = Persistent<FunctionTemplate>::New(consoleTemplate);
//prototype
Handle<ObjectTemplate> consolePrototype = consoleTemplate->PrototypeTemplate();
//attaching method
consolePrototype->Set("log", FunctionTemplate::New(log));
//creating instance
Handle<ObjectTemplate> consoleInstance = consoleTemplate->InstanceTemplate();
consoleInstance->SetInternalFieldCount(1);
//Image :
//template
Handle<FunctionTemplate> imageTemplate = FunctionTemplate::New();
imageTemplate->SetClassName(v8::String::New("Image"));
CanvasContextV8Bindings::imageTemplate = Persistent<FunctionTemplate>::New(imageTemplate);
//prototype
Handle<ObjectTemplate> imagePrototype = imageTemplate->PrototypeTemplate();
//creating instance
Handle<ObjectTemplate> imageInstance = imageTemplate->InstanceTemplate();
imageInstance->SetInternalFieldCount(1);
//Canvas gradient :
//template
Handle<FunctionTemplate> canvasGradientTemplate = FunctionTemplate::New();
canvasGradientTemplate->SetClassName(v8::String::New("CanvasGradient"));
CanvasContextV8Bindings::canvasGradientTemplate = Persistent<FunctionTemplate>::New(canvasGradientTemplate);
//prototype
Handle<ObjectTemplate> canvasGradientPrototype = canvasGradientTemplate->PrototypeTemplate();
//creating instance
Handle<ObjectTemplate> canvasGradientInstance = canvasGradientTemplate->InstanceTemplate();
canvasGradientInstance->SetInternalFieldCount(1);
//attaching method
canvasGradientPrototype->Set("addColorStop", FunctionTemplate::New(addColorStop));
//Canvas Pattern :
//template
Handle<FunctionTemplate> canvasPatternTemplate = FunctionTemplate::New();
canvasPatternTemplate->SetClassName(v8::String::New("CanvasPattern"));
CanvasContextV8Bindings::canvasPatternTemplate = Persistent<FunctionTemplate>::New(canvasPatternTemplate);
//prototype
Handle<ObjectTemplate> canvasPatternPrototype = canvasPatternTemplate->PrototypeTemplate();
//creating instance
Handle<ObjectTemplate> canvasPatternInstance = canvasPatternTemplate->InstanceTemplate();
canvasPatternInstance->SetInternalFieldCount(1);
//Canvas context :
//template
Handle<FunctionTemplate> canvasContextTemplate = FunctionTemplate::New();
canvasContextTemplate->SetClassName(v8::String::New("CanvasContext"));
//prototype
Handle<ObjectTemplate> canvasContextPrototype = canvasContextTemplate->PrototypeTemplate();
//attaching method
//2D Context
canvasContextPrototype->Set("save", FunctionTemplate::New(save));
canvasContextPrototype->Set("restore", FunctionTemplate::New(restore));
//Transformation
canvasContextPrototype->Set("scale", FunctionTemplate::New(scale));
canvasContextPrototype->Set("rotate", FunctionTemplate::New(rotate));
canvasContextPrototype->Set("translate", FunctionTemplate::New(translate));
canvasContextPrototype->Set("transform", FunctionTemplate::New(transform));
canvasContextPrototype->Set("setTransform", FunctionTemplate::New(setTransform));
//Image drawing
canvasContextPrototype->Set("drawImage", FunctionTemplate::New(drawImage));
//Colors, styles and shadows
canvasContextPrototype->Set("createLinearGradient", FunctionTemplate::New(createLinearGradient));
canvasContextPrototype->Set("createRadialGradient", FunctionTemplate::New(createRadialGradient));
canvasContextPrototype->Set("createPattern", FunctionTemplate::New(createPattern));
//Paths
canvasContextPrototype->Set("beginPath", FunctionTemplate::New(beginPath));
//.........这里部分代码省略.........