Changeset 8390 in orxonox.OLD for branches/script_engine/src
- Timestamp:
- Jun 14, 2006, 3:33:04 PM (19 years ago)
- Location:
- branches/script_engine/src/lib/script_engine
- Files:
-
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/Makefile.am
r8271 r8390 13 13 14 14 libORXscript_a_SOURCES = \ 15 script.cc\ 16 script_manager.cc\ 17 script_class.cc\ 15 script.cc \ 16 script_manager.cc \ 17 script_class.cc \ 18 script_method.cc \ 19 \ 18 20 account.cc \ 19 21 object.cc … … 25 27 lunar.h\ 26 28 script.h\ 27 script_manager.h\ 28 script_class.h 29 script_manager.h \ 30 script_class.h \ 31 script_method.h 29 32 30 33 … … 32 35 33 36 check_PROGRAMS = example 34 35 36 37 38 39 40 41 37 example_DEPENDENCIES = \ 42 38 $(MAINSRCDIR)/world_entities/libORXwe.a \ 43 39 $(libORXlibs_a_LIBRARIES_) \ 44 40 $(MAINSRCDIR)/util/libORXutils.a 45 46 41 example_LDADD = \ 47 42 $(MAINSRCDIR)/util/libORXutils.a \ -
branches/script_engine/src/lib/script_engine/script.cc
r8380 r8390 95 95 { 96 96 printf("Script %p: I am about to add %s of class %s\n",this,objectName.c_str(),className.c_str()); 97 97 98 98 BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS); 99 99 printf("The script class for %s is at %p \n",className.c_str(),scriptClass); … … 171 171 reportError(error); 172 172 //clean up 173 currentFunction.assign(""); 173 currentFunction.assign(""); 174 174 argumentCount = returnCount = 0; 175 175 return false; … … 184 184 else 185 185 printf("Error: no function selected.\n"); 186 186 187 187 return false; 188 188 } … … 241 241 int Script::getReturnedInt() 242 242 { 243 int returnValue ;243 int returnValue = 0; 244 244 if(returnCount > 0) 245 245 { … … 257 257 bool Script::getReturnedBool() 258 258 { 259 bool returnValue ;259 bool returnValue = false; 260 260 if(returnCount > 0) 261 261 { … … 272 272 float Script::getReturnedFloat() 273 273 { 274 float returnValue ;274 float returnValue = 0.0f; 275 275 if(returnCount > 0) 276 276 { … … 287 287 void Script::getReturnedString(std::string& string) 288 288 { 289 const char* returnValue ;289 const char* returnValue = ""; 290 290 if(returnCount > 0) 291 291 { -
branches/script_engine/src/lib/script_engine/script_class.cc
r8271 r8390 17 17 18 18 #include "script_class.h" 19 20 using namespace std;21 22 19 23 20 /** -
branches/script_engine/src/lib/script_engine/script_class.h
r8289 r8390 11 11 #include "script.h" 12 12 #include "lunar.h" 13 14 // FORWARD DECLARATION15 16 13 17 14 /** … … 28 25 { 29 26 30 31 27 public: 28 virtual ~ScriptClass(); 32 29 33 34 30 bool operator==(const std::string& name) { return (this->getName() == name); } 31 bool operator==(ClassID classID) { return (this->classID == classID); } 35 32 36 37 33 virtual void registerClass(Script* script) = 0; 34 virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0; 38 35 39 40 36 protected: 37 ScriptClass(const std::string& name, ClassID classID); 41 38 42 43 39 private: 40 ClassID classID; 44 41 }; 45 42 … … 50 47 class tScriptable : public ScriptClass 51 48 { 52 53 54 55 49 public: 50 tScriptable(const std::string& name, ClassID classID) 51 : ScriptClass(name, classID) 52 { } 56 53 57 virtual void registerClass(Script* script) 58 { 59 Lunar<T>::Register(script); 60 } 61 virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) 62 { 63 return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc); 64 } 65 66 67 68 } 69 ; 54 virtual void registerClass(Script* script) 55 { 56 Lunar<T>::Register(script); 57 } 58 virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) 59 { 60 return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc); 61 } 62 }; 70 63 71 64 -
branches/script_engine/src/lib/script_engine/script_method.cc
r8387 r8390 16 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 17 17 18 #include "script_class.h" 19 20 using namespace std; 21 18 #include "script_method.h" 22 19 23 20 /** 24 * standard constructor21 * @param standard constructor 25 22 * @todo this constructor is not jet implemented - do it 26 23 */ 27 ScriptClass::ScriptClass(const std::string& name, ClassID classID) 28 : BaseObject(name) 24 ScriptMethod::ScriptMethod(const std::string& methodName, const Executor& executor) 29 25 { 30 this->setClassID(CL_SCRIPT_CLASS, "ScriptClass"); 31 this->classID = classID; 26 this->addMethod(methodName, executor); 32 27 } 33 28 29 ScriptMethod& ScriptMethod::addMethod(const std::string& methodName, const Executor& executor) 30 { 31 this->methods.push_back(ScriptMethod::Method(methodName, executor)); 32 33 return *this; 34 } 35 36 ScriptMethod::Method::Method(const std::string& name, const Executor& executor) 37 { 38 this->name = name; 39 this->executor = executor.clone(); 40 } 34 41 35 42 /** 36 43 * standard deconstructor 37 44 */ 38 Script Class::~ScriptClass()45 ScriptMethod::~ScriptMethod() 39 46 { 40 // delete what has to be deleted here 47 for (unsigned int i = 0; i < methods.size(); i ++) 48 { 49 delete methods[i].executor; 50 }; 41 51 } 52 53 54 -
branches/script_engine/src/lib/script_engine/script_method.h
r8387 r8390 4 4 */ 5 5 6 #ifndef _SCRIPT_ CLASS_H7 #define _SCRIPT_ CLASS_H6 #ifndef _SCRIPT_METHOD_H 7 #define _SCRIPT_METHOD_H 8 8 9 #include "base_object.h"9 #include <vector> 10 10 11 #include "script.h"12 11 #include "lunar.h" 13 14 // FORWARD DECLARATION 12 #include "executor/executor_lua.h" 15 13 16 14 17 /** 18 * Creates a factory to a Loadable Class. 19 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file) 20 */ 21 #define CREATE_SCRIPTABLE_CLASS(CLASS_NAME, CLASS_ID) \ 22 tScriptable<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_ID) 15 class ScriptMethod 16 { 17 public: 18 ScriptMethod(const std::string& methodName, const Executor& executor); 19 ~ScriptMethod(); 20 21 ScriptMethod& addMethod(const std::string& methodName, const Executor& executor); 23 22 24 23 24 private: 25 struct Method 26 { 27 Method(const std::string& name, const Executor& executor); 28 std::string name; 29 Executor* executor; 30 }; 25 31 26 //! A class for ... 27 class ScriptClass : protected BaseObject 28 { 29 30 public: 31 virtual ~ScriptClass(); 32 33 bool operator==(const std::string& name) { return (this->getName() == name); } 34 bool operator==(ClassID classID) { return (this->classID == classID); } 35 36 virtual void registerClass(Script* script) = 0; 37 virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0; 38 39 protected: 40 ScriptClass(const std::string& name, ClassID classID); 41 42 private: 43 ClassID classID; 32 std::vector<Method> methods; 44 33 }; 45 34 46 47 48 49 template <class T> 50 class tScriptable : public ScriptClass 51 { 52 public: 53 tScriptable(const std::string& name, ClassID classID) 54 : ScriptClass(name, classID) 55 { } 56 57 virtual void registerClass(Script* script) 58 { 59 Lunar<T>::Register(script); 60 } 61 virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) 62 { 63 return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc); 64 } 65 66 67 68 } 69 ; 70 71 72 #endif /* _SCRIPT_CLASS_H */ 35 #endif /* _SCRIPT_METHOD_H */
Note: See TracChangeset
for help on using the changeset viewer.