Changeset 3500
- Timestamp:
- 03/15/10 06:22:08 (5 months ago)
- Location:
- Core/branches/0075_TR_SCRIPTING/Scripting
- Files:
-
- 4 modified
-
I_ScriptModule.hpp (modified) (5 diffs)
-
I_ScriptType.hpp (modified) (3 diffs)
-
script_type.hpp (modified) (3 diffs)
-
script_type_impl.hpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Core/branches/0075_TR_SCRIPTING/Scripting/I_ScriptModule.hpp
r1074 r3500 2 2 // Zen Core Framework 3 3 // 4 // Copyright (C) 2001 - 20 09Tony Richards4 // Copyright (C) 2001 - 2010 Tony Richards 5 5 // Copyright (C) 2008 - 2009 Matthew Alan Gray 6 6 // … … 31 31 #include <Zen/Core/Memory/managed_ptr.hpp> 32 32 #include <Zen/Core/Memory/managed_weak_ptr.hpp> 33 #include <Zen/Core/Memory/managed_self_ref.hpp> 34 33 35 #include <Zen/Core/Event/Event.hpp> 34 36 … … 50 52 /// the modules nonetheless. 51 53 class SCRIPTING_DLL_LINK I_ScriptModule 54 : public Memory::managed_self_ref<I_ScriptModule> 52 55 { 53 56 /// @name Types … … 67 70 /// @{ 68 71 public: 69 /// Create a type or class 72 /// Create a type or class. 70 73 /// @param _typeName name of the type as exposed to the scripting language. Some languages 71 74 /// prepend the module name (such as Python). … … 83 86 virtual void activate() = 0; 84 87 85 /// Create a new script object and binds it to a C++ object 88 /// Create a new script object and binds it to a C++ object. 86 89 /// @param _name Name of the object 87 90 /// @param _pType Type of the object 88 91 /// @param _pObject C++ version of the object 89 /// @todo90 92 virtual void createObject(pScriptType_type _pType, I_ObjectReference* _pObject) = 0; 91 93 92 /// Create a new global script object and binds it to a C++ object 94 /// Create a new global script object and binds it to a C++ object. 93 95 /// @param _name Name of the object 94 96 /// @param _pType Type of the object -
Core/branches/0075_TR_SCRIPTING/Scripting/I_ScriptType.hpp
r3256 r3500 44 44 class I_ObjectReference; 45 45 class I_ScriptMethod; 46 class I_ScriptModule; 46 47 47 48 class SCRIPTING_DLL_LINK I_ScriptType … … 53 54 typedef Zen::Memory::managed_weak_ptr<I_ScriptType> wpScriptType_type; 54 55 typedef Zen::Event::Event<wpScriptType_type> scriptTypeEvent_type; 56 typedef Zen::Memory::managed_ptr<I_ScriptModule> pScriptModule_type; 55 57 56 58 typedef I_ObjectReference* pObjectReference_type; … … 70 72 typedef int(*int_function_no_args_type)(pObjectReference_type); 71 73 typedef int(*int_function_args_type)(pObjectReference_type, std::vector<boost::any>); 72 /// @}74 /// @} 73 75 74 76 /// @name I_ScriptType interface 75 77 /// @{ 76 78 public: 79 /// Get the module to which this type belongs. 80 virtual pScriptModule_type getScriptModule() = 0; 81 82 /// Get the name of this type. 83 virtual const std::string& getTypeName() = 0; 84 85 /// Get the documentation / short description of this type. 86 virtual const std::string& getDocumentation() = 0; 87 77 88 /// Add a method to this type that takes no arguments and returns void 78 89 virtual void addMethod(const std::string& _name, const std::string& _docString, void_function_no_args_type _function) = 0; -
Core/branches/0075_TR_SCRIPTING/Scripting/script_type.hpp
r3407 r3500 57 57 typedef std::map<std::string, I_ScriptMethod*> Methods_type; 58 58 typedef Zen::Memory::managed_ptr<I_ScriptType> pScriptType_type; 59 typedef Zen::Memory::managed_ptr<I_ScriptModule> pScriptModule_type; 60 typedef Zen::Memory::managed_weak_ptr<I_ScriptModule> wpScriptModule_type; 59 61 typedef std::map<std::string, I_ScriptableType*> GlobalObjects_type; 60 62 /// @} … … 83 85 /// Create a global instance of this script type. 84 86 void createGlobalObject(const std::string& _objectName, I_ScriptableType* _pScriptableObject); 87 88 /// Get the script module for this type. 89 /// This will not always return a valid script module depending 90 /// upon the state of this script_type. 91 /// Look at the documentation of the constructors of this class for more information. 92 pScriptModule_type getScriptModule(); 85 93 /// @} 86 94 87 95 /// @name 'Structors. 88 /// These methods are only called by script_module.96 /// 89 97 /// @{ 98 public: 99 /// Construct a script type that adds to an existing script type whose 100 /// module has not yet been activated. After adding methods to this script_type, 101 /// invoke the script_type::activate() method to register the methods. 102 /// getScriptModule() will return a valid script module if this constructor 103 /// is used. 104 script_type(pScriptType_type pScriptType_type); 90 105 private: 91 106 friend class script_module; 92 107 /// Create a script type. 108 /// This constructor is invoked by script_module. 109 /// getScriptModule() will return a valid script module if this constructor 110 /// is used only after _module::activate() has been invoked. 93 111 script_type(script_module& _module, const std::string& _typeName, const std::string& _documentation); 94 112 /// @} … … 98 116 private: 99 117 /// Script module that contains this script type. 100 script_module& m_module; 118 /// This is the template version. Either m_pModule or m_pScriptModule 119 /// are valid, but generally not both. 120 /// @see m_pScriptModule 121 script_module* m_pModule; 122 123 /// Script module that contains this script type. 124 /// This is the interface version. 125 /// @see m_pModule 126 wpScriptModule_type m_pScriptModule; 101 127 102 128 /// Name of this script_type. -
Core/branches/0075_TR_SCRIPTING/Scripting/script_type_impl.hpp
r3407 r3500 40 40 inline 41 41 script_type<ScriptableClass_type>::script_type(script_module& _module, const std::string& _typeName, const std::string& _documentation) 42 : m_module(_module) 42 : m_pModule(&_module) 43 , m_pScriptModule() 43 44 , m_typeName(_typeName) 44 45 , m_documentation(_documentation) 46 { 47 } 48 49 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 50 template<typename ScriptableClass_type> 51 inline 52 script_type<ScriptableClass_type>::script_type(pScriptType_type _pScriptType) 53 : m_pModule(NULL) 54 , m_pScriptModule(_pScriptType->getScriptModule()) 55 , m_typeName(_pScriptType->getTypeName()) 56 , m_documentation(_pScriptType->getDocumentation()) 57 , m_pScriptType(_pScriptType) 45 58 { 46 59 } … … 90 103 script_type<ScriptableClass_type>::activate() 91 104 { 92 m_pScriptType = m_module.getScriptModule()->createScriptType(m_typeName, m_documentation, 0); 105 // Create m_pScriptType if it hasn't already been created. 106 if (!m_pScriptType.isValid()) 107 { 108 m_pScriptType = getScriptModule()->createScriptType(m_typeName, m_documentation, 0); 109 } 93 110 94 111 // Iterate through the script_method and register them. 95 112 for(Methods_type::iterator iter = m_methods.begin(); iter != m_methods.end(); iter++) 96 113 { 97 // TODO I_ScriptMethod needs to support documentation 114 // TODO I_ScriptMethod needs to support documentation. For now the second 115 // parameter is simply an empty string. 98 116 m_pScriptType->addMethod(iter->first, "", iter->second); 99 117 } … … 110 128 for(GlobalObjects_type::iterator iter = m_globalObjects.begin(); iter != m_globalObjects.end(); iter++) 111 129 { 112 m_module.getScriptModule()->createGlobalObject(iter->first, m_pScriptType, iter->second->getScriptObject());130 getScriptModule()->createGlobalObject(iter->first, m_pScriptType, iter->second->getScriptObject()); 113 131 } 114 132 … … 121 139 script_type<ScriptableClass_type>::createGlobalObject(const std::string& _objectName, I_ScriptableType* _pScriptableObject) 122 140 { 123 // Defer this until after the module has been activated. 141 // Defer the creation of the object until after the module has been activated. 142 // For now, keep a collection of global objects, and when the module 143 // is activated, create them using createGlobals() 124 144 m_globalObjects[_objectName] = _pScriptableObject; 145 } 146 147 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 148 template<typename ScriptableClass_type> 149 inline 150 Zen::Memory::managed_ptr<I_ScriptModule> 151 script_type<ScriptableClass_type>::getScriptModule() 152 { 153 if(m_pModule) 154 { 155 return m_pModule->getScriptModule(); 156 } 157 else 158 { 159 return m_pScriptModule.lock(); 160 } 125 161 } 126 162
