Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jun 14, 2006, 5:50:18 PM (19 years ago)
Author:
bensch
Message:

trunk: merged the script_engine branche back here
merged with command
svn merge https://svn.orxonox.net/orxonox/branches/script_engine . -r8284:HEAD
no conflicts

File:
1 edited

Legend:

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

    r8271 r8408  
    2323  luaopen_math(luaState);
    2424  luaopen_debug(luaState);
    25 
    2625  if (root != NULL)
    2726    this->loadParams(root);
     
    3837void Script::loadParams(const TiXmlElement* root)
    3938{
     39  //printf("Loading params for %p \n",this);
    4040  BaseObject::loadParams(root);
    4141
     
    7777     else
    7878     {
    79       reportError(error);
    80      }
    81 
    82    }
    83    else
    84    {
     79       printf("ERROR while loading file %s: \n",filename.c_str());
     80       reportError(error);
     81     }
     82
     83   }
     84   else
     85   {
     86     printf("ERROR while loading file %s: \n",filename.c_str());
    8587     reportError(error);
    8688   }
     
    9294 void Script::addObject(const std::string& className, const std::string& objectName)
    9395 {
     96   //printf("Script %p: I am about to add %s of class %s\n",this,objectName.c_str(),className.c_str());
     97
    9498   BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
     99   //printf("The script class for %s is at %p \n",className.c_str(),scriptClass);
    95100   WorldObject tmpObj;
    96101   if (scriptClass != NULL)
     
    103108
    104109     BaseObject* object = ClassList::getObject(objectName, className);
     110     //printf("%s is at %p \n",objectName.c_str(),object);
    105111     if (object != NULL && !objectIsAdded(objectName))
    106112     {
     
    162168    if(error != 0)
    163169    {
     170     printf("ERROR while executing function %s: \n",currentFunction.c_str());
    164171     reportError(error);
     172     //clean up
     173     currentFunction.assign("");
     174     argumentCount = returnCount = 0;
    165175     return false;
    166176    }
     
    174184   else
    175185     printf("Error: no function selected.\n");
     186
     187   return false;
    176188 }
    177189
     
    229241 int Script::getReturnedInt()
    230242 {
    231    int returnValue;
     243   int returnValue = 0;
    232244   if(returnCount > 0)
    233245   {
    234      if(lua_isnumber(luaState, -1))
    235      {
    236        returnValue = (int)lua_tonumber(luaState, -1);
     246     if(lua_isnumber(luaState, -1*returnCount))
     247     {
     248       returnValue = (int)lua_tonumber(luaState, -1*returnCount);
     249       lua_remove(luaState,-1*returnCount);
    237250       returnCount--;
    238        lua_pop(luaState,1);
     251       
    239252     }
    240253   }
     
    245258 bool Script::getReturnedBool()
    246259 {
    247    bool returnValue;
     260   bool returnValue = false;
    248261   if(returnCount > 0)
    249262   {
    250      if(lua_isboolean(luaState, -1))
    251      {
    252        returnValue = (bool)lua_toboolean(luaState, -1);
     263     if(lua_isboolean(luaState, -1*returnCount))
     264     {
     265       returnValue = (bool)lua_toboolean(luaState, -1*returnCount);
     266       lua_remove(luaState,-1*returnCount);
    253267       returnCount--;
    254        lua_pop(luaState,1);
    255268     }
    256269   }
     
    260273float Script::getReturnedFloat()
    261274 {
    262    float returnValue;
     275   float returnValue = 0.0f;
    263276   if(returnCount > 0)
    264277   {
    265      if(lua_isnumber(luaState, -1))
    266      {
    267        returnValue = (float)lua_tonumber(luaState, -1);
     278     if(lua_isnumber(luaState, -1*returnCount))
     279     {
     280       returnValue = (float)lua_tonumber(luaState, -1*returnCount);
     281       lua_remove(luaState,-1*returnCount);
    268282       returnCount--;
    269        lua_pop(luaState,1);
    270283     }
    271284   }
     
    275288 void Script::getReturnedString(std::string& string)
    276289 {
    277    const char* returnValue;
     290   const char* returnValue = "";
    278291   if(returnCount > 0)
    279292   {
    280      if(lua_isstring(luaState, -1))
    281      {
    282        returnValue = lua_tostring(luaState, -1);
     293     if(lua_isstring(luaState, -1*returnCount))
     294     {
     295       returnValue = lua_tostring(luaState, -1*returnCount);
     296       lua_remove(luaState,-1*returnCount);
    283297       returnCount--;
    284        lua_pop(luaState,1);
    285298     }
    286299   }
     
    296309  fprintf(stderr, "ERROR: %s\n", msg);
    297310  lua_pop(luaState, 1);
     311 }
    298312  return error;
    299313 }
    300  }
    301314
    302315
Note: See TracChangeset for help on using the changeset viewer.