void Widget::PrototypeMethodsInit(Handle<FunctionTemplate> constructor_template) { HandleScope scope; Actor::PrototypeMethodsInit(constructor_template); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("disabled"), Widget::DisabledGetter, Widget::DisabledSetter); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("className"), Widget::ClassNameGetter, Widget::ClassNameSetter); NODE_SET_PROTOTYPE_METHOD(constructor_template, "applyStyle", Widget::ApplyStyle); }
void Table::PrototypeMethodsInit(Handle<FunctionTemplate> constructor_template) { HandleScope scope; /* Inherit methods from Actor */ Container::PrototypeMethodsInit(constructor_template); Stylable::PrototypeMethodsInit(constructor_template); /* Accessor */ constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("columnSpacing"), Table::ColumnSpacingGetter, Table::ColumnSpacingSetter); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("rowSpacing"), Table::RowSpacingGetter, Table::RowSpacingSetter); /* Methods */ NODE_SET_PROTOTYPE_METHOD(constructor_template, "_add", Table::Add); }
Handle<Object> HoneydNodeJs::WrapBroadcast(Broadcast* bcast) { HandleScope scope; if (broadcastTemplate.IsEmpty() ) { Handle<FunctionTemplate> protoTemplate = FunctionTemplate::New(); protoTemplate->InstanceTemplate()->SetInternalFieldCount(1); broadcastTemplate = Persistent<FunctionTemplate>::New(protoTemplate); Local<Template> proto = broadcastTemplate->PrototypeTemplate(); proto->Set("GetScript", FunctionTemplate::New(InvokeMethod<string, Broadcast, &Nova::Broadcast::GetScript>) ); proto->Set("GetSrcPort", FunctionTemplate::New(InvokeMethod<int, Broadcast, &Nova::Broadcast::GetSrcPort>) ); proto->Set("GetDstPort", FunctionTemplate::New(InvokeMethod<int, Broadcast, &Nova::Broadcast::GetDstPort>) ); proto->Set("GetTime", FunctionTemplate::New(InvokeMethod<int, Broadcast, &Nova::Broadcast::GetTime>) ); } // Get the constructor from the template Handle<Function> ctor = broadcastTemplate->GetFunction(); // Instantiate the object with the constructor Handle<Object> result = ctor->NewInstance(); // Wrap the native object in an handle and set it in the internal field to get at later. Handle<External> broadcastPtr = External::New(bcast); result->SetInternalField(0,broadcastPtr); return scope.Close(result); }
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()); }
Local<Object> PairNodeIterator::New(int type, MapType::const_iterator new_iter, MapType::const_iterator new_end) { Handle<FunctionTemplate> tmplt; if ((PairNodeIterator::KEY_TYPE & type) && (PairNodeIterator::VALUE_TYPE & type)) { tmplt = NanNew<FunctionTemplate>(key_value_tmplt); } else if (KEY_TYPE & type) { tmplt = NanNew<FunctionTemplate>(key_tmplt); } else { tmplt = NanNew<FunctionTemplate>(value_tmplt); } Local<Object> obj = tmplt->InstanceTemplate()->NewInstance(); PairNodeIterator *iter = new PairNodeIterator(new_iter, new_end); iter->Wrap(obj); Local<String> key = NanNew<String>("key"); Local<String> value = NanNew<String>("value"); Local<String> done = NanNew<String>("done"); if (PairNodeIterator::KEY_TYPE & type) { obj->SetAccessor(key, GetKey); } if (PairNodeIterator::VALUE_TYPE & type) { obj->SetAccessor(value, GetValue); } obj->SetAccessor(done, GetDone); return obj; }
bool bind_Base(Handle<Object> parent) { ScriptingManager* pManager = ScriptingManager::getSingletonPtr(); Handle<FunctionTemplate> base = pManager->getClassTemplate("Tests.Base"); if (base.IsEmpty()) { // Declaration of the class base = FunctionTemplate::New(Base_New); base->InstanceTemplate()->SetInternalFieldCount(1); // Attributes AddAttribute(base, "a", Base_GetA, Base_SetA); // Methods AddMethod(base, "f", Base_F); AddMethod(base, "g", Base_G); // Register the class with the Scripting Manager pManager->declareClassTemplate("Tests.Base", base); } // Add the class to the parent return parent->Set(String::New("Base"), base->GetFunction()); }
Handle<Object> HoneydNodeJs::WrapPortSet(PortSet *portSet) { HandleScope scope; // Setup the template for the type if it hasn't been already if( portSetTemplate.IsEmpty() ) { Handle<FunctionTemplate> protoTemplate = FunctionTemplate::New(); protoTemplate->InstanceTemplate()->SetInternalFieldCount(1); portSetTemplate = Persistent<FunctionTemplate>::New(protoTemplate); // Javascript methods Local<Template> proto = portSetTemplate->PrototypeTemplate(); proto->Set("GetTCPBehavior", FunctionTemplate::New(InvokeMethod<std::string, Nova::PortSet, &Nova::PortSet::GetTCPBehavior>) ); proto->Set("GetUDPBehavior", FunctionTemplate::New(InvokeMethod<std::string, Nova::PortSet, &Nova::PortSet::GetUDPBehavior>) ); proto->Set("GetICMPBehavior", FunctionTemplate::New(InvokeMethod<std::string, Nova::PortSet, &Nova::PortSet::GetICMPBehavior>) ); proto->Set(String::NewSymbol("GetPorts"),FunctionTemplate::New(GetPorts)->GetFunction()); } // Get the constructor from the template Handle<Function> ctor = portSetTemplate->GetFunction(); // Instantiate the object with the constructor Handle<Object> result = ctor->NewInstance(); // Wrap the native object in an handle and set it in the internal field to get at later. Handle<External> portSetPtr = External::New(portSet); result->SetInternalField(0,portSetPtr); return scope.Close(result); }
void Shape::Initialize(Handle<Object> target) { HandleScope scope; Handle<FunctionTemplate> c = FunctionTemplate::New(Shape::New); c->InstanceTemplate()->SetInternalFieldCount(1); c->SetClassName(String::NewSymbol("shapeObj")); SET_ATTRIBUTE_RO(c, "numvalues", getProp); SET_ATTRIBUTE_RO(c, "numlines", getProp); SET_ATTRIBUTE_RO(c, "index", getProp); SET_ATTRIBUTE_RO(c, "type", getProp); SET_ATTRIBUTE_RO(c, "tileindex", getProp); SET_ATTRIBUTE_RO(c, "classindex", getProp); SET_ATTRIBUTE(c, "text", getProp, setProp); NODE_SET_PROTOTYPE_METHOD(c, "clone", clone); NODE_SET_PROTOTYPE_METHOD(c, "line", getLine); NODE_SET_PROTOTYPE_METHOD(c, "add", addLine); NODE_SET_PROTOTYPE_METHOD(c, "setGeometry", setGeometry); NODE_DEFINE_CONSTANT(c->GetFunction(), "Point",MS_SHAPE_POINT); NODE_DEFINE_CONSTANT(c->GetFunction(), "Line",MS_SHAPE_LINE); NODE_DEFINE_CONSTANT(c->GetFunction(), "Polygon",MS_SHAPE_POLYGON); NODE_DEFINE_CONSTANT(c->GetFunction(), "Null",MS_SHAPE_NULL); target->Set(String::NewSymbol("shapeObj"), c->GetFunction()); constructor.Reset(Isolate::GetCurrent(), c); }
Handle<Object> HoneydNodeJs::WrapPort(Port *port) { HandleScope scope; // Setup the template for the type if it hasn't been already if( m_portTemplate.IsEmpty() ) { Handle<FunctionTemplate> nodeTemplate = FunctionTemplate::New(); nodeTemplate->InstanceTemplate()->SetInternalFieldCount(1); m_portTemplate = Persistent<FunctionTemplate>::New(nodeTemplate); // Javascript methods Local<Template> proto = m_portTemplate->PrototypeTemplate(); proto->Set("GetPortName", FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetPortName>) ); proto->Set("GetPortNum", FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetPortNum>) ); proto->Set("GetType", FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetType>) ); proto->Set("GetBehavior", FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetBehavior>) ); proto->Set("GetScriptName", FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetScriptName>) ); proto->Set("GetService", FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetService>) ); proto->Set("GetIsInherited", FunctionTemplate::New(InvokeMethod<bool, Nova::Port, &Nova::Port::GetIsInherited>) ); } // Get the constructor from the template Handle<Function> ctor = m_portTemplate->GetFunction(); // Instantiate the object with the constructor Handle<Object> result = ctor->NewInstance(); // Wrap the native object in an handle and set it in the internal field to get at later. Handle<External> portPtr = External::New(port); result->SetInternalField(0,portPtr); return scope.Close(result); }
Handle<Object> HoneydNodeJs::WrapNode(Node* node) { HandleScope scope; // Setup the template for the type if it hasn't been already if( m_NodeTemplate.IsEmpty() ) { Handle<FunctionTemplate> nodeTemplate = FunctionTemplate::New(); nodeTemplate->InstanceTemplate()->SetInternalFieldCount(1); m_NodeTemplate = Persistent<FunctionTemplate>::New(nodeTemplate); // Javascript methods Local<Template> proto = m_NodeTemplate->PrototypeTemplate(); proto->Set("GetName", FunctionTemplate::New(InvokeMethod<string, Node, &Nova::Node::GetName>) ); proto->Set("GetInterface", FunctionTemplate::New(InvokeMethod<string, Node, &Nova::Node::GetInterface>) ); proto->Set("GetProfile", FunctionTemplate::New(InvokeMethod<string, Node, &Nova::Node::GetProfile>) ); proto->Set("GetIP", FunctionTemplate::New(InvokeMethod<string, Node, &Nova::Node::GetIP>) ); proto->Set("GetMAC", FunctionTemplate::New(InvokeMethod<string, Node, &Nova::Node::GetMAC>) ); proto->Set("IsEnabled", FunctionTemplate::New(InvokeMethod<bool, Node, &Nova::Node::IsEnabled>) ); } // Get the constructor from the template Handle<Function> ctor = m_NodeTemplate->GetFunction(); // Instantiate the object with the constructor Handle<Object> result = ctor->NewInstance(); // Wrap the native object in an handle and set it in the internal field to get at later. Handle<External> nodePtr = External::New(node); result->SetInternalField(0,nodePtr); return scope.Close(result); }
void init_v8() { printf("init_v8 called\n"); V8::Initialize(); // Get the default Isolate created at startup. Isolate* isolate = Isolate::GetCurrent(); // Create a stack-allocated handle scope. HandleScope handle_scope(isolate); symbol_templ = FunctionTemplate::New(); //get the point's instance template Handle<ObjectTemplate> symbol_templ_template = symbol_templ->InstanceTemplate(); //set its internal field count to one (we'll put references to the C++ point here later) symbol_templ_template->SetInternalFieldCount(1); symbol_templ_template->SetAccessor(String::New("name"), GetSymbolName, 0); printf("init_v8 done\n"); v8_is_initialized = true; }
bool bind_Signals_Signal(Handle<Object> parent) { ScriptingManager* pManager = ScriptingManager::getSingletonPtr(); Handle<FunctionTemplate> signal = pManager->getClassTemplate("Athena.Signals.Signal"); if (signal.IsEmpty()) { // Declaration of the class signal = FunctionTemplate::New(Signal_New); signal->InstanceTemplate()->SetInternalFieldCount(1); // Attributes AddAttribute(signal, "disconnected", Signal_IsDisconnected, 0); // Methods AddMethod(signal, "connect", Signal_Connect); AddMethod(signal, "disconnect", Signal_Disconnect); AddMethod(signal, "fire", Signal_Fire); pManager->declareClassTemplate("Athena.Signals.Signal", signal); } // Add the class to the parent return parent->Set(String::New("Signal"), signal->GetFunction()); }
void Toggle::PrototypeMethodsInit(Handle<FunctionTemplate> constructor_template) { HandleScope scope; Widget::PrototypeMethodsInit(constructor_template); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("active"), Toggle::ActiveGetter, Toggle::ActiveSetter); }
void BoxLayout::PrototypeMethodsInit(Handle<FunctionTemplate> constructor_template) { HandleScope scope; /* Inherit methods from Actor */ Container::PrototypeMethodsInit(constructor_template); Widget::PrototypeMethodsInit(constructor_template); Stylable::PrototypeMethodsInit(constructor_template); /* Accessor */ constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("orientation"), BoxLayout::OrientationGetter, BoxLayout::OrientationSetter); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("spacing"), BoxLayout::SpacingGetter, BoxLayout::SpacingSetter); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("enableAnimations"), BoxLayout::EnableAnimationsGetter, BoxLayout::EnableAnimationsSetter); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("scrollToFocused"), BoxLayout::ScrollToFocusedGetter, BoxLayout::ScrollToFocusedSetter); /* Methods */ NODE_SET_PROTOTYPE_METHOD(constructor_template, "_add", BoxLayout::Add); NODE_SET_PROTOTYPE_METHOD(constructor_template, "_setExpand", BoxLayout::SetExpand); }
Handle<FunctionTemplate> fl_shad_GetTemplate() { HandleScope handle_scope; Handle<FunctionTemplate> templ = FunctionTemplate::New(); Handle<ObjectTemplate> instance_templ = templ->InstanceTemplate(); instance_templ->Set("addFragmentShader", FunctionTemplate::New(fl_shad_AddFragmentShader)); instance_templ->Set("addVertexShader", FunctionTemplate::New(fl_shad_AddVertexShader)); instance_templ->Set("linkShader", FunctionTemplate::New(fl_shad_LinkShader)); instance_templ->SetInternalFieldCount(1); return handle_scope.Close(templ); }
void Image::PrototypeMethodsInit(Handle<FunctionTemplate> constructor_template) { HandleScope scope; Widget::PrototypeMethodsInit(constructor_template); Stylable::PrototypeMethodsInit(constructor_template); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("scaleMode"), Image::ScaleModeGetter, Image::ScaleModeSetter); NODE_SET_PROTOTYPE_METHOD(constructor_template, "loadFile", Image::LoadFile); }
void Texture::PrototypeMethodsInit(Handle<FunctionTemplate> constructor_template) { HandleScope scope; Actor::PrototypeMethodsInit(constructor_template); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("filterQuality"), Texture::FilterQualityGetter, Texture::FilterQualitySetter); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("repeatX"), Texture::RepeatXGetter, Texture::RepeatXSetter); constructor_template->InstanceTemplate()->SetAccessor(String::NewSymbol("repeatY"), Texture::RepeatYGetter, Texture::RepeatYSetter); NODE_SET_PROTOTYPE_METHOD(constructor_template, "loadFile", Texture::LoadFile); NODE_SET_PROTOTYPE_METHOD(constructor_template, "loadFileSync", Texture::LoadFileSync); NODE_SET_PROTOTYPE_METHOD(constructor_template, "keepAspectRatio", Texture::KeepAspectRatio); NODE_SET_PROTOTYPE_METHOD(constructor_template, "on", Texture::On); #if USE_X11 /* Sync X11 window */ NODE_SET_PROTOTYPE_METHOD(constructor_template, "setX11Window", Texture::SetX11Window); NODE_SET_PROTOTYPE_METHOD(constructor_template, "setX11WindowAutoSync", Texture::SetX11WindowAutoSync); #endif }
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); }
Handle<Object> HoneydNodeJs::WrapProfile(NodeProfile *pfile) { HandleScope scope; // Setup the template for the type if it hasn't been already if( m_profileTemplate.IsEmpty() ) { Handle<FunctionTemplate> nodeTemplate = FunctionTemplate::New(); nodeTemplate->InstanceTemplate()->SetInternalFieldCount(1); m_profileTemplate = Persistent<FunctionTemplate>::New(nodeTemplate); // Javascript methods Local<Template> proto = m_profileTemplate->PrototypeTemplate(); proto->Set("GetName", FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetName>)); proto->Set("GetPortNames", FunctionTemplate::New(InvokeMethod<std::vector<std::string>, NodeProfile, &Nova::NodeProfile::GetPortNames>)); proto->Set("GetTcpAction", FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetTcpAction>)); proto->Set("GetUdpAction", FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetUdpAction>)); proto->Set("GetIcmpAction", FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetIcmpAction>)); proto->Set("GetPersonality", FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetPersonality>)); proto->Set("GetEthernet", FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetEthernet>)); proto->Set("GetUptimeMin", FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetUptimeMin>)); proto->Set("GetUptimeMax", FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetUptimeMax>)); proto->Set("GetDropRate", FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetDropRate>)); proto->Set("GetGenerated", FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::GetGenerated>)); proto->Set("GetDistribution", FunctionTemplate::New(InvokeMethod<double, NodeProfile, &Nova::NodeProfile::GetDistribution>)); proto->Set("GetParentProfile", FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetParentProfile>)); proto->Set("GetVendors", FunctionTemplate::New(InvokeMethod<std::vector<std::string>, NodeProfile, &Nova::NodeProfile::GetVendors>)); proto->Set("GetVendorDistributions", FunctionTemplate::New(InvokeMethod<std::vector<double>, NodeProfile, &Nova::NodeProfile::GetVendorDistributions>)); proto->Set("isTcpActionInherited", FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isTcpActionInherited>)); proto->Set("isUdpActionInherited", FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isUdpActionInherited>)); proto->Set("isIcmpActionInherited", FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isIcmpActionInherited>)); proto->Set("isPersonalityInherited",FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isPersonalityInherited>)); proto->Set("isEthernetInherited", FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isEthernetInherited>)); proto->Set("isUptimeInherited", FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isUptimeInherited>)); proto->Set("isDropRateInherited", FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isDropRateInherited>)); } // Get the constructor from the template Handle<Function> ctor = m_profileTemplate->GetFunction(); // Instantiate the object with the constructor Handle<Object> result = ctor->NewInstance(); // Wrap the native object in an handle and set it in the internal field to get at later. Handle<External> profilePtr = External::New(pfile); result->SetInternalField(0,profilePtr); return scope.Close(result); }
bool bind_Transforms(Handle<Object> parent) { ScriptingManager* pManager = ScriptingManager::getSingletonPtr(); Handle<FunctionTemplate> transforms = pManager->getClassTemplate("Athena.Entities.Transforms"); if (transforms.IsEmpty()) { assert(!pManager->getClassTemplate("Athena.Entities.Component").IsEmpty()); // Declaration of the class transforms = FunctionTemplate::New(Transforms_New); transforms->InstanceTemplate()->SetInternalFieldCount(1); transforms->Inherit(pManager->getClassTemplate("Athena.Entities.Component")); // Attributes AddAttribute(transforms, "position", Transforms_GetPosition, Transforms_SetPosition); AddAttribute(transforms, "worldPosition", Transforms_GetWorldPosition, 0); AddAttribute(transforms, "orientation", Transforms_GetOrientation, Transforms_SetOrientation); AddAttribute(transforms, "worldOrientation", Transforms_GetWorldOrientation, 0); AddAttribute(transforms, "inheritOrientation", Transforms_GetInheritOrientation, Transforms_SetInheritOrientation); AddAttribute(transforms, "scale", Transforms_GetScale, Transforms_SetScale); AddAttribute(transforms, "worldScale", Transforms_GetWorldScale, 0); AddAttribute(transforms, "inheritScale", Transforms_GetInheritScale, Transforms_SetInheritScale); // Methods AddMethod(transforms, "translate", Transforms_Translate); AddMethod(transforms, "setDirection", Transforms_SetDirection); AddMethod(transforms, "lookAt", Transforms_LookAt); AddMethod(transforms, "roll", Transforms_Roll); AddMethod(transforms, "pitch", Transforms_Pitch); AddMethod(transforms, "yaw", Transforms_Yaw); AddMethod(transforms, "rotate", Transforms_Rotate); AddMethod(transforms, "resetOrientation", Transforms_ResetOrientation); AddMethod(transforms, "rescale", Transforms_Rescale); pManager->declareClassTemplate("Athena.Entities.Transforms", transforms); parent->Set(String::New("Transforms_TYPE"), String::New(Athena::Entities::Transforms::TYPE.c_str())); parent->Set(String::New("TS_LOCAL"), Uint32::New(Transforms::TS_LOCAL)); parent->Set(String::New("TS_PARENT"), Uint32::New(Transforms::TS_PARENT)); parent->Set(String::New("TS_WORLD"), Uint32::New(Transforms::TS_WORLD)); } // Add the class to the parent return parent->Set(String::New("Transforms"), transforms->GetFunction()); }
void Scrollable::PrototypeMethodsInit(Handle<FunctionTemplate> constructor_template) { HandleScope scope; Local<String> name = String::NewSymbol("scroll"); /* Scrollable Object */ Handle<ObjectTemplate> ObjectTpl = ObjectTemplate::New(); ObjectTpl->SetInternalFieldCount(1); Local<Object> ObjectInstance = ObjectTpl->NewInstance(); /* Methods */ NODE_SET_METHOD(ObjectInstance, "test", Scrollable::Test); constructor_template->InstanceTemplate()->Set(name, ObjectInstance); }
Handle<FunctionTemplate> Projection::MakeProjectionTemplate() { HandleScope scope; Handle<FunctionTemplate> t = FunctionTemplate::New(New); // Setup "Static" Members t->Set(String::NewSymbol("transform"), FunctionTemplate::New(Transform)); // Setup Instance Members Local<ObjectTemplate> obj_t = t->InstanceTemplate(); obj_t->SetInternalFieldCount(1); obj_t->Set(String::NewSymbol("__projVersion"), String::New(pj_get_release())); obj_t->SetAccessor(String::NewSymbol("definition"), GetDefinition); return scope.Close(t); }
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; }
Handle<FunctionTemplate> Geometry::MakeGeometryTemplate() { HandleScope scope; Handle<FunctionTemplate> t = FunctionTemplate::New(New); Local<ObjectTemplate> obj_t = t->InstanceTemplate(); obj_t->SetInternalFieldCount(1); obj_t->Set(String::NewSymbol("_geosVersion"), String::New(GEOSversion())); obj_t->SetAccessor(String::NewSymbol("envelope"), GetEnvelope); obj_t->SetAccessor(String::NewSymbol("convexHull"), GetConvexHull); obj_t->SetAccessor(String::NewSymbol("boundary"), GetBoundary); obj_t->SetAccessor(String::NewSymbol("pointOnSurface"), GetPointOnSurface); obj_t->SetAccessor(String::NewSymbol("centroid"), GetCentroid); obj_t->SetAccessor(String::NewSymbol("srid"), GetSRID, SetSRID); obj_t->SetAccessor(String::NewSymbol("type"), GetType); obj_t->SetAccessor(String::NewSymbol("area"), GetArea); obj_t->SetAccessor(String::NewSymbol("length"), GetLength); return scope.Close(t); }
void ScriptSystem::SetupContext() { HandleScope handle_scope; if(!mGlobalContext.IsEmpty()) { mGlobalContext.Dispose(); } // create a template for the global object Handle<ObjectTemplate> global = ObjectTemplate::New(); // create persistent global context mGlobalContext = Persistent<Context>::New(Context::New(NULL, global)); // store pointer to script system into isolate data to have it globally available in javascript Isolate::GetCurrent()->SetData(this); RegisterGlobalFunctions(this, mGlobalContext); RegisterPropertyFunctions(this, mGlobalContext); InitializeAllWrappers(GetEntityManager()); Handle<Context> context = GetGlobalContext(); Context::Scope context_scope(context); Handle<FunctionTemplate> tmplt = FunctionTemplate::New(); tmplt->InstanceTemplate()->SetInternalFieldCount(2); tmplt->SetClassName(String::New("ScriptSystem")); context->Global()->Set(String::New("Screen"), WrapScreen(this)); dtEntity::InputInterface* ipiface = dtEntity::GetInputInterface(); if(ipiface) { context->Global()->Set(String::New("Input"), WrapInputInterface(GetGlobalContext(), ipiface)); context->Global()->Set(String::New("Axis"), WrapAxes(ipiface)); context->Global()->Set(String::New("Key"), WrapKeys(ipiface)); } context->Global()->Set(String::New("TouchPhase"), WrapTouchPhases()); context->Global()->Set(String::New("Priority"), WrapPriorities()); context->Global()->Set(String::New("Order"), WrapPriorities()); }
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); }
bool bind_Scene(Handle<Object> parent) { ScriptingManager* pManager = ScriptingManager::getSingletonPtr(); Handle<FunctionTemplate> scene = pManager->getClassTemplate("Athena.Entities.Scene"); if (scene.IsEmpty()) { // Declaration of the class scene = FunctionTemplate::New(Scene_New); scene->InstanceTemplate()->SetInternalFieldCount(1); // Attributes AddAttribute(scene, "name", Scene_GetName, 0); AddAttribute(scene, "enabled", Scene_GetEnabled, Scene_SetEnabled); AddAttribute(scene, "shown", Scene_GetShown, Scene_SetShown); AddAttribute(scene, "nbEntities", Scene_GetNbEntities, 0); AddAttribute(scene, "components", Scene_GetComponentsList, 0); AddAttribute(scene, "nbComponents", Scene_GetNbComponents, 0); AddAttribute(scene, "signals", Scene_GetSignalsList, 0); // Methods - Entities management AddMethod(scene, "create", Scene_CreateEntity); AddMethod(scene, "getEntity", Scene_GetEntity); AddMethod(scene, "destroy", Scene_DestroyEntity); AddMethod(scene, "destroyAll", Scene_DestroyAll); AddMethod(scene, "transfer", Scene_Transfer); // Methods - Components management AddMethod(scene, "getComponent", Scene_GetComponent); AddMethod(scene, "getMainComponent", Scene_GetMainComponent); pManager->declareClassTemplate("Athena.Entities.Scene", scene); } // Add the class to the parent return parent->Set(String::New("Scene"), scene->GetFunction()); }
Handle<Object> HoneydNodeJs::WrapProfile(Profile *pfile) { HandleScope scope; // Setup the template for the type if it hasn't been already if( profileTemplate.IsEmpty() ) { Handle<FunctionTemplate> protoTemplate = FunctionTemplate::New(); protoTemplate->InstanceTemplate()->SetInternalFieldCount(1); profileTemplate = Persistent<FunctionTemplate>::New(protoTemplate); // Javascript methods Local<Template> proto = profileTemplate->PrototypeTemplate(); proto->Set("GetName", FunctionTemplate::New(InvokeMethod<std::string, Profile, &Nova::Profile::GetName>)); proto->Set("GetPersonality", FunctionTemplate::New(InvokeMethod<std::string, const Profile, &Nova::Profile::GetPersonality>)); proto->Set("GetUptimeMin", FunctionTemplate::New(InvokeMethod<uint, const Profile, &Nova::Profile::GetUptimeMin>)); proto->Set("GetUptimeMax", FunctionTemplate::New(InvokeMethod<uint, const Profile, &Nova::Profile::GetUptimeMax>)); proto->Set("GetDropRate", FunctionTemplate::New(InvokeMethod<std::string, const Profile, &Nova::Profile::GetDropRate>)); proto->Set("GetCount", FunctionTemplate::New(InvokeMethod<uint32_t, Profile, &Nova::Profile::GetCount>)); proto->Set("GetParentProfile", FunctionTemplate::New(InvokeMethod<std::string, const Profile, &Nova::Profile::GetParentProfile>)); proto->Set("GetVendors", FunctionTemplate::New(InvokeMethod<std::vector<std::string>, Profile, &Nova::Profile::GetVendors>)); proto->Set("GetVendorCounts", FunctionTemplate::New(InvokeMethod<std::vector<uint>, Profile, &Nova::Profile::GetVendorCounts>)); proto->Set("IsPersonalityInherited",FunctionTemplate::New(InvokeMethod<bool, const Profile, &Nova::Profile::IsPersonalityInherited>)); proto->Set("IsUptimeInherited", FunctionTemplate::New(InvokeMethod<bool, const Profile, &Nova::Profile::IsUptimeInherited>)); proto->Set("IsDropRateInherited", FunctionTemplate::New(InvokeMethod<bool, const Profile, &Nova::Profile::IsDropRateInherited>)); } // Get the constructor from the template Handle<Function> ctor = profileTemplate->GetFunction(); // Instantiate the object with the constructor Handle<Object> result = ctor->NewInstance(); // Wrap the native object in an handle and set it in the internal field to get at later. Handle<External> profilePtr = External::New(pfile); result->SetInternalField(0,profilePtr); return scope.Close(result); }
Handle<Object> HoneydNodeJs::WrapScript(Nova::Script *script) { HandleScope scope; if (scriptTemplate.IsEmpty()) { Handle<FunctionTemplate> protoTemplate = FunctionTemplate::New(); protoTemplate->InstanceTemplate()->SetInternalFieldCount(1); scriptTemplate = Persistent<FunctionTemplate>::New(protoTemplate); // Javascript methods Local<Template> proto = scriptTemplate->PrototypeTemplate(); proto->Set("GetName", FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetName>) ); proto->Set("GetService", FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetService>) ); proto->Set("GetOsClass", FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetOsClass>) ); proto->Set("GetPath", FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetPath>) ); proto->Set("GetDefaultProtocol", FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetDefaultProtocol>) ); proto->Set("GetDefaultPort", FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetDefaultPort>) ); proto->Set("GetIsConfigurable", FunctionTemplate::New(InvokeMethod<bool, Nova::Script, &Nova::Script::GetIsConfigurable>) ); proto->Set("GetOptions", FunctionTemplate::New(InvokeMethod<std::map<std::string, std::vector<std::string>> , Nova::Script, &Nova::Script::GetOptions>) ); proto->Set("GetOptionDescriptions", FunctionTemplate::New(InvokeMethod<std::map<std::string, std::string> , Nova::Script, &Nova::Script::GetOptionDescriptions>) ); } // Get the constructor from the template Handle<Function> ctor = scriptTemplate->GetFunction(); // Instantiate the object with the constructor Handle<Object> result = ctor->NewInstance(); // Wrap the native object in an handle and set it in the internal field to get at later. Handle<External> scriptPtr = External::New(script); result->SetInternalField(0,scriptPtr); return scope.Close(result); }
void Player::RegisterFunctionTemplate(Handle<FunctionTemplate>& func) { auto object = func->InstanceTemplate(); /** * プレイヤーのIDを返します * * このIDは1から始まる連番値です。 * * @method id * @return {Integer} プレイヤーのID */ object->Set(String::New("id"), FunctionTemplate::New(Function_Player_id)); /** * プレイヤーの名前を返します * * @method name * @return {String} プレイヤーの名前 */ object->Set(String::New("name"), FunctionTemplate::New(Function_Player_name)); /** * プレイヤーのトリップを返します * * @method trip * @return {String|Undefined} プレイヤーのトリップ。トリップが指定されていないときは、Undefinedを返します。 */ object->Set(String::New("trip"), FunctionTemplate::New(Function_Player_trip)); /** * プレイヤーのログイン状態を返します * * @method login * @return {Boolean} ログインしている時trueを返します */ object->Set(String::New("login"), FunctionTemplate::New(Function_Player_login)); /** * プレイヤーチャンネルを返します * * @method channel * @return {Integer} ログインしている時trueを返します */ object->Set(String::New("channel"), FunctionTemplate::New(Function_Player_channel)); /** * プレイヤーの頭上の吹き出しに表示する内容を設定します * * @method setBalloonContent * @param {String} text 表示するテキスト */ object->Set(String::New("setBalloonContent"), FunctionTemplate::New(Function_Player_setBalloonContent)); /** * プレイヤーの座標を返します * * @method position * @return {Array} */ object->Set(String::New("position"), FunctionTemplate::New(Function_Player_position)); ///** //* プレイヤーにタグを追加します //* //* @method addTag //* @param {String} tag タグ //*/ ///** //* プレイヤーにタグがついていればtrueを追加します //* //* @method hasTag //* @param {String} tag タグ //* @return {Boolean} タグがついているかどうか //*/ ///** //* プレイヤーからタグを削除します //* //* @method removeTag //* @param {String} tag タグ //*/ ///** //* プレイヤーからタグをすべて削除します //* //* @method clearTag //*/ object->SetInternalFieldCount(1); }