Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9869 in orxonox.OLD for trunk/src/lib/script_engine/script.cc


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/script_engine/script.cc

    r9298 r9869  
    1818#include "luaincl.h"
    1919#include "debug.h"
    20 #include "util/loading/resource_manager.h"
    21 
     20
     21#include "loading/resource_manager.h"
    2222#include "loading/load_param.h"
    2323#include "parser/tinyxml/tinyxml.h"
    2424
    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))
     25ObjectListDefinition(Script);
     26
     27CREATE_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))
    3132                     );
     33
    3234
    3335Script::Script(const TiXmlElement* root)
    3436{
    35   this->setClassID(CL_SCRIPT, "Script");
     37  this->registerObject(this, Script::_objectList);
    3638
    3739  returnCount = argumentCount = 0;
     
    5254Script::Script(const std::string& filename)
    5355{
    54   this->setClassID(CL_SCRIPT, "Script");
     56  this->registerObject(this, Script::_objectList);
    5557
    5658  returnCount = argumentCount = 0;
     
    6466  luaopen_math(luaState);
    6567  luaopen_debug(luaState);
    66  
     68
    6769  this->loadFile(filename);
    6870
     
    98100bool Script::loadFile(const std::string& filename)
    99101 {
    100    std::string filedest(ResourceManager::getInstance()->getDataDir());
    101    filedest += "scripts/" + filename;
    102    
     102   std::string filedest(Resources::ResourceManager::getInstance()->mainGlobalPath().name());
     103   filedest += "/scripts/" + filename;
     104
    103105   this->addThisScript();
    104106   this->registerStandartClasses();
    105    
     107
    106108   if(currentFile.length() != 0)
    107109   {
     
    142144   //printf(("Script %s: I am about to add %s of class %s\n",this->getName(),objectName.c_str(),className.c_str());
    143145
    144    BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
     146   ScriptClass* scriptClass = ScriptClass::objectList().getObject(className);
    145147  // printf(("The script class for %s is at %p \n",className.c_str(),scriptClass);
    146148   WorldObject tmpObj;
     
    150152     if( !classIsRegistered(className) )
    151153     {
    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);
    156158    // printf(("%s is at %p \n",objectName.c_str(),object);
    157159     if (object != NULL && !objectIsAdded(objectName))
    158160     {
    159         static_cast<ScriptClass*>(scriptClass)->insertObject(this, object, false);
     161        scriptClass->insertObject(this, object, false);
    160162        tmpObj.name = objectName;
    161163        registeredObjects.push_back(tmpObj);
     
    169171 bool Script::executeFile()
    170172 {
    171    PRINT(2)("WARNING: script.executeFile is not implemented yet\n");
     173   PRINTF(2)("script.executeFile is not implemented yet\n");
    172174   /*if(currentFile.length() != 0)
    173175   {
     
    214216    if(error != 0)
    215217    {
    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());
    217219     reportError(error);
    218220     //clean up
     
    229231   }
    230232   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());
    232234
    233235   return false;
     
    295297       lua_remove(luaState,-1*returnCount);
    296298       returnCount--;
    297        
     299
    298300     }
    299301   }
     
    352354void Script::addThisScript()
    353355{
    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);
    359362   }
    360363}
     
    375378 {
    376379   bool success = false;
    377    
     380
    378381   //this->registerClass(std::string("Vector"));
    379382    this->registerClass("ScriptTrigger");
     
    382385   return success;
    383386 }
    384  
    385  
     387
     388
    386389 void Script::registerClass( const std::string& className)
    387390 {
    388    BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
     391   ScriptClass* scriptClass = ScriptClass::objectList().getObject(className);
    389392   //printf(("The script class for %s is at %p \n",className.c_str(),scriptClass);
     393
    390394   WorldObject tmpObj;
    391395   if (scriptClass != NULL)
     
    400404     }
    401405   }
    402  
     406
    403407 }
    404408
Note: See TracChangeset for help on using the changeset viewer.