Changeset 9869 in orxonox.OLD for trunk/src/lib/script_engine/script.cc
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/script_engine/script.cc
r9298 r9869 18 18 #include "luaincl.h" 19 19 #include "debug.h" 20 #include "util/loading/resource_manager.h" 21 20 21 #include "loading/resource_manager.h" 22 22 #include "loading/load_param.h" 23 23 #include "parser/tinyxml/tinyxml.h" 24 24 25 #include "class_list.h" 26 CREATE_SCRIPTABLE_CLASS(Script, CL_SCRIPT, 27 addMethod("addObject", ExecutorLua2<Script,const std::string&, const std::string& >(&Script::addObject)) 28 ->addMethod("registerClass", ExecutorLua1<Script,const std::string&>(&Script::registerClass)) 29 ->addMethod("selectFunction", ExecutorLua2ret<Script, bool, const std::string&, int >(&Script::selectFunction)) 30 ->addMethod("executeFunction", ExecutorLua0ret<Script,bool >(&Script::executeFunction)) 25 ObjectListDefinition(Script); 26 27 CREATE_SCRIPTABLE_CLASS(Script, 28 addMethod("addObject", Executor2<Script, lua_State*,const std::string&, const std::string& >(&Script::addObject)) 29 ->addMethod("registerClass", Executor1<Script, lua_State*,const std::string&>(&Script::registerClass)) 30 ->addMethod("selectFunction", Executor2ret<Script, lua_State*, bool, const std::string&, int >(&Script::selectFunction)) 31 ->addMethod("executeFunction", Executor0ret<Script, lua_State*,bool >(&Script::executeFunction)) 31 32 ); 33 32 34 33 35 Script::Script(const TiXmlElement* root) 34 36 { 35 this-> setClassID(CL_SCRIPT, "Script");37 this->registerObject(this, Script::_objectList); 36 38 37 39 returnCount = argumentCount = 0; … … 52 54 Script::Script(const std::string& filename) 53 55 { 54 this-> setClassID(CL_SCRIPT, "Script");56 this->registerObject(this, Script::_objectList); 55 57 56 58 returnCount = argumentCount = 0; … … 64 66 luaopen_math(luaState); 65 67 luaopen_debug(luaState); 66 68 67 69 this->loadFile(filename); 68 70 … … 98 100 bool Script::loadFile(const std::string& filename) 99 101 { 100 std::string filedest(Resource Manager::getInstance()->getDataDir());101 filedest += " scripts/" + filename;102 102 std::string filedest(Resources::ResourceManager::getInstance()->mainGlobalPath().name()); 103 filedest += "/scripts/" + filename; 104 103 105 this->addThisScript(); 104 106 this->registerStandartClasses(); 105 107 106 108 if(currentFile.length() != 0) 107 109 { … … 142 144 //printf(("Script %s: I am about to add %s of class %s\n",this->getName(),objectName.c_str(),className.c_str()); 143 145 144 BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);146 ScriptClass* scriptClass = ScriptClass::objectList().getObject(className); 145 147 // printf(("The script class for %s is at %p \n",className.c_str(),scriptClass); 146 148 WorldObject tmpObj; … … 150 152 if( !classIsRegistered(className) ) 151 153 { 152 static_cast<ScriptClass*>(scriptClass)->registerClass(this);153 } 154 155 BaseObject* object = ClassList::getObject(objectName, className);154 scriptClass->registerClass(this); 155 } 156 157 BaseObject* object = ObjectListBase::getBaseObject(className, objectName); 156 158 // printf(("%s is at %p \n",objectName.c_str(),object); 157 159 if (object != NULL && !objectIsAdded(objectName)) 158 160 { 159 s tatic_cast<ScriptClass*>(scriptClass)->insertObject(this, object, false);161 scriptClass->insertObject(this, object, false); 160 162 tmpObj.name = objectName; 161 163 registeredObjects.push_back(tmpObj); … … 169 171 bool Script::executeFile() 170 172 { 171 PRINT (2)("WARNING:script.executeFile is not implemented yet\n");173 PRINTF(2)("script.executeFile is not implemented yet\n"); 172 174 /*if(currentFile.length() != 0) 173 175 { … … 214 216 if(error != 0) 215 217 { 216 printf("SCRIPT %s : ERROR: Failed to execute function %s: \n",currentFile.c_str(),currentFunction.c_str());218 PRINTF(1)("Script '%s' : Failed to execute function '%s': \n",currentFile.c_str(),currentFunction.c_str()); 217 219 reportError(error); 218 220 //clean up … … 229 231 } 230 232 else 231 printf("SCRIPT %s : ERROR: no function selected.\n",currentFile.c_str());233 PRINTF(1)("SCRIPT '%s' : no function selected.\n",currentFile.c_str()); 232 234 233 235 return false; … … 295 297 lua_remove(luaState,-1*returnCount); 296 298 returnCount--; 297 299 298 300 } 299 301 } … … 352 354 void Script::addThisScript() 353 355 { 354 BaseObject* scriptClass = ClassList::getObject("Script", CL_SCRIPT_CLASS); 355 if (scriptClass != NULL) 356 { 357 static_cast<ScriptClass*>(scriptClass)->registerClass(this); 358 static_cast<ScriptClass*>(scriptClass)->insertObject(this, this,"thisscript", false); 356 ScriptClass* scriptClass = ScriptClass::objectList().getObject("Script"); 357 358 if (scriptClass != NULL) 359 { 360 scriptClass->registerClass(this); 361 scriptClass->insertObject(this, this,"thisscript", false); 359 362 } 360 363 } … … 375 378 { 376 379 bool success = false; 377 380 378 381 //this->registerClass(std::string("Vector")); 379 382 this->registerClass("ScriptTrigger"); … … 382 385 return success; 383 386 } 384 385 387 388 386 389 void Script::registerClass( const std::string& className) 387 390 { 388 BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);391 ScriptClass* scriptClass = ScriptClass::objectList().getObject(className); 389 392 //printf(("The script class for %s is at %p \n",className.c_str(),scriptClass); 393 390 394 WorldObject tmpObj; 391 395 if (scriptClass != NULL) … … 400 404 } 401 405 } 402 406 403 407 } 404 408
Note: See TracChangeset
for help on using the changeset viewer.