Ticket #2517: global_components.diff
File global_components.diff, 5.0 KB (added by , 10 years ago) |
---|
-
source/simulation2/system/ComponentManager.cpp
69 69 // these functions, so we skip registering them here in those cases 70 70 if (!skipScriptFunctions) 71 71 { 72 m_ScriptInterface.RegisterFunction<void, int, std::string, CScriptVal, CComponentManager::Script_RegisterComponentType> ("RegisterComponentType"); 72 m_ScriptInterface.RegisterFunction<void, int, std::string, CScriptVal, CComponentManager::Script_RegisterNewComponentType> ("RegisterComponentType"); 73 m_ScriptInterface.RegisterFunction<void, int, std::string, CScriptVal, CComponentManager::Script_ReRegisterComponentType> ("ReRegisterComponentType"); 73 74 m_ScriptInterface.RegisterFunction<void, std::string, CComponentManager::Script_RegisterInterface> ("RegisterInterface"); 74 75 m_ScriptInterface.RegisterFunction<void, std::string, CComponentManager::Script_RegisterMessageType> ("RegisterMessageType"); 75 76 m_ScriptInterface.RegisterFunction<void, std::string, CScriptVal, CComponentManager::Script_RegisterGlobal> ("RegisterGlobal"); … … 143 144 return ok; 144 145 } 145 146 146 void CComponentManager::Script_RegisterComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, std::string cname, CScriptVal ctor )147 void CComponentManager::Script_RegisterComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, std::string cname, CScriptVal ctor, bool reRegister) 147 148 { 148 149 CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); 149 150 JSContext* cx = componentManager->m_ScriptInterface.GetContext(); … … 163 164 ComponentTypeId cid = componentManager->LookupCID(cname); 164 165 if (cid == CID__Invalid) 165 166 { 167 if (reRegister) 168 { 169 componentManager->m_ScriptInterface.ReportError("ReRegistering component type that was not registered before"); // TODO: report the actual name 170 return; 171 } 166 172 // Allocate a new cid number 167 173 cid = componentManager->m_NextScriptComponentTypeId++; 168 174 componentManager->m_ComponentTypeIdsByName[cname] = cid; … … 171 177 { 172 178 // Component type is already loaded, so do hotloading: 173 179 174 if (!componentManager->m_CurrentlyHotloading )180 if (!componentManager->m_CurrentlyHotloading && !reRegister) 175 181 { 176 182 componentManager->m_ScriptInterface.ReportError("Registering component type with already-registered name"); // TODO: report the actual name 177 183 return; … … 182 188 // We can only replace scripted component types, not native ones 183 189 if (ctPrevious.type != CT_Script) 184 190 { 185 componentManager->m_ScriptInterface.ReportError(" Hotloading script component type with same name as native component");191 componentManager->m_ScriptInterface.ReportError("Loading script component type with same name as native component"); 186 192 return; 187 193 } 188 194 … … 303 309 } 304 310 } 305 311 312 void CComponentManager::Script_RegisterNewComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, std::string cname, CScriptVal ctor) 313 { 314 CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); 315 componentManager->Script_RegisterComponentType(pCxPrivate, iid, cname, ctor, false); 316 componentManager->m_ScriptInterface.SetGlobal(cname.c_str(), ctor, componentManager->m_CurrentlyHotloading); 317 } 318 319 void CComponentManager::Script_ReRegisterComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, std::string cname, CScriptVal ctor) 320 { 321 CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); 322 componentManager->Script_RegisterComponentType(pCxPrivate, iid, cname, ctor, true); 323 } 324 306 325 void CComponentManager::Script_RegisterInterface(ScriptInterface::CxPrivate* pCxPrivate, std::string name) 307 326 { 308 327 CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); -
source/simulation2/system/ComponentManager.h
242 242 243 243 private: 244 244 // Implementations of functions exposed to scripts 245 static void Script_RegisterComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, std::string cname, CScriptVal ctor); 245 static void Script_RegisterComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, std::string cname, CScriptVal ctor, bool reRegister); 246 static void Script_ReRegisterComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, std::string cname, CScriptVal ctor); 247 static void Script_RegisterNewComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, std::string cname, CScriptVal ctor); 246 248 static void Script_RegisterInterface(ScriptInterface::CxPrivate* pCxPrivate, std::string name); 247 249 static void Script_RegisterMessageType(ScriptInterface::CxPrivate* pCxPrivate, std::string name); 248 250 static void Script_RegisterGlobal(ScriptInterface::CxPrivate* pCxPrivate, std::string name, CScriptVal value);