Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10381 in orxonox.OLD


Ignore:
Timestamp:
Jan 26, 2007, 5:29:26 PM (17 years ago)
Author:
patrick
Message:

merged script branche to turnk

Location:
trunk/src
Files:
4 edited

Legend:

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

    r10321 r10381  
    111111   if(currentFile.length() != 0)
    112112   {
    113      printf("SCRIPT %s : ERROR: Could not load %s because an other file is already loaded: %s\n",currentFile.c_str(),filename.c_str(), currentFile.c_str());
     113     printf("ERROR IN SCRIPT %s :  Could not load %s because an other file is already loaded: %s\n",currentFile.c_str(),filename.c_str(), currentFile.c_str());
    114114     return false;
    115115    }
     
    119119   if(error == 0)
    120120   {
    121      currentFile = filename;
     121     currentFile = file;
    122122     error = lua_pcall(luaState, 0, 0, 0);
    123123
     
    128128     else
    129129     {
    130        printf("SCRIPT %s : ERROR: while loading file %s: \n",currentFile.c_str(),filename.c_str());
    131130       reportError(error);
    132131     }
     
    135134   else
    136135   {
    137      printf("SCRIPT %s : ERROR: while loading file %s: \n",currentFile.c_str(),filename.c_str());
    138136     reportError(error);
    139137   }
    140138
    141    printf("SCRIPT : ERROR: while loading file %s \n",filename.c_str());
     139   printf("ERROR IN SCRIPT:  Could not load file %s \n",filename.c_str());
    142140   return false;
    143141 }
     
    166164        tmpObj.name = objectName;
    167165        registeredObjects.push_back(tmpObj);
    168      }
    169    }
    170  }
    171 
     166        return;
     167     }
     168   }
     169   printf("ERROR IN SCRIPT %s: Could not add %s of class %s\n",this->currentFile.c_str(),objectName.c_str(),className.c_str());
     170 }
     171
     172
     173void Script::addObjectAsName( const std::string& className, const std::string& objectName, const std::string& nameInScript)
     174 {
     175   ScriptClass* scriptClass = ScriptClass::objectList().getObject(className);
     176   WorldObject tmpObj;
     177   if (scriptClass != NULL)
     178   {
     179     tmpObj.type = className;
     180     if( !classIsRegistered(className) )
     181     {
     182       scriptClass->registerClass(this);
     183     }
     184     BaseObject* object = ObjectListBase::getBaseObject(className, objectName);
     185     if (object != NULL && !objectIsAdded(objectName))
     186     {
     187        scriptClass->insertObject(this, object,nameInScript, false);
     188        tmpObj.name = objectName;
     189        registeredObjects.push_back(tmpObj);
     190        return;
     191     }
     192   }
     193   printf("ERROR IN SCRIPT %s: Could not add %s of class %s\n",this->currentFile.c_str(),objectName.c_str(),className.c_str());
     194 }
    172195
    173196
     
    208231   }
    209232   else
    210      printf("SCRIPT %s : ERROR: There is an other function active ( %s ) or there are unremoved return values on the stack. Please remove them first.\n",currentFile.c_str(),currentFunction.c_str());
     233     printf("ERROR IN SCRIPT %s :  There is an other function active ( %s ) or there are unremoved return values on the stack. Please remove them first.\n",currentFile.c_str(),currentFunction.c_str());
    211234   return false;
    212235 }
     
    235258   }
    236259   else
    237      PRINTF(1)("SCRIPT '%s' : no function selected.\n",currentFile.c_str());
     260     PRINTF(1)("SCRIPT '%s' : No function selected.\n",currentFile.c_str());
    238261
    239262   return false;
     
    252275   else
    253276   {
    254      printf("SCRIPT %s : ERROR: Couldn't add parameter because the wrong function is selected: %s instead of %s\n",currentFile.c_str(), currentFunction.c_str(), toFunction.c_str());
     277     printf("ERROR IN SCRIPT %s :  Couldn't add parameter because the wrong function is selected: %s instead of %s\n",currentFile.c_str(), currentFunction.c_str(), toFunction.c_str());
    255278    return false;
    256279   }
     
    269292   else
    270293   {
    271      printf("SCRIPT %s : ERROR: Couldn't add parameter because the wrong function is selected: %s instead of %s\n",currentFile.c_str(), currentFunction.c_str(), toFunction.c_str());
     294     printf("ERROR IN SCRIPT %s :  Couldn't add parameter because the wrong function is selected: %s instead of %s\n",currentFile.c_str(), currentFunction.c_str(), toFunction.c_str());
    272295     return false;
    273296   }
     
    285308   else
    286309   {
    287      printf("SCRIPT %s : ERROR: Couldn't add parameter because the wrong function is selected: %s instead of %s\n",currentFile.c_str(), currentFunction.c_str(), toFunction.c_str());
     310     printf("ERROR IN SCRIPT %s : Couldn't add parameter because the wrong function is selected: %s instead of %s\n",currentFile.c_str(), currentFunction.c_str(), toFunction.c_str());
    288311     return false;
    289312   }
     
    320343     }
    321344     else
    322        printf("SCRIPT %s : ERROR: Trying to retreive non bolean value\n",this->currentFile.c_str());
     345       printf("ERROR IN SCRIPT %s : Trying to retreive non bolean value\n",this->currentFile.c_str());
    323346   }
    324347   return returnValue;
     
    373396  const char *msg = lua_tostring(luaState, -1);
    374397  if (msg == NULL) msg = "(error with no message)\n";
    375   printf("ERROR: %s\n", msg);
     398  printf("ERROR IN SCRIPT %s : %s\n",currentFile.c_str(), msg);
    376399  lua_pop(luaState, 1);
    377400 }
  • trunk/src/lib/script_engine/script.h

    r9869 r10381  
    3434    bool loadFile(const std::string& filename);
    3535    void addObject( const std::string& className,const std::string& objectName);
     36    void addObjectAsName( const std::string& className,const std::string& objectName, const std::string& nameInScript);
    3637    void registerClass(const std::string& className);                           //!< Register a class but dont add any instances
    3738
  • trunk/src/lib/script_engine/script_class.cc

    r9916 r10381  
    2525CREATE_SCRIPTABLE_CLASS(Script,
    2626                    addMethod("addObject", Executor2<Script, lua_State*,const std::string&, const std::string& >(&Script::addObject))
     27                    ->addMethod("addObjectAsName", Executor3<Script, lua_State*,const std::string&, const std::string&, const std::string& >(&Script::addObjectAsName))
    2728                    ->addMethod("registerClass", Executor1<Script, lua_State*,const std::string&>(&Script::registerClass))
    2829                    ->addMethod("selectFunction", Executor2ret<Script, lua_State*, bool, const std::string&, int >(&Script::selectFunction))
  • trunk/src/world_entities/script_trigger.cc

    r10374 r10381  
    148148  else
    149149  {
    150     PRINTF(2)("Target %s for %s::%s does not Exist\n", target.c_str(), this->getClassCName(), this->getCName());
     150    PRINTF(2)("ERROR SCRTIPTTRIGGER : Target %s for %s::%s does not Exist\n", target.c_str(), this->getClassCName(), this->getCName());
    151151  }
    152152}
     
    167167  else
    168168  {
    169     PRINTF(2)("Parent %s for %s::%s does not Exist\n", parent.c_str(), this->getClassCName(), this->getCName());
     169    PRINTF(2)("ERROR SCRTIPTTRIGGER : Parent %s for %s::%s does not Exist\n", parent.c_str(), this->getClassCName(), this->getCName());
    170170  }
    171171}
     
    213213       //testScriptingFramework();
    214214    if(!(script->selectFunction(this->functionName,returnCount)) )
    215       PRINT(1)("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
     215      PRINT(1)("ERROR SCRTIPTTRIGGER : Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
    216216
    217217    script->pushParam( timestep, this->functionName);
    218218
    219219    if( !(script->executeFunction()) )
    220       PRINT(1)("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
     220      PRINT(1)("ERROR SCRTIPTTRIGGER : Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
    221221
    222222    scriptFinished = script->getReturnedBool();
    223223  }
     224  else
     225  printf("ERROR SCRTIPTTRIGGER : Script could not be executed !\n");
    224226
    225227
     
    238240      scriptIsOk = true;
    239241    }
     242    else
     243    printf("ERROR SCRTIPTTRIGGER : Could not find the wrapperobject of %s , the script won't be executed ! \n", file.c_str());
    240244  }
    241245}
Note: See TracChangeset for help on using the changeset viewer.