Changeset 8408 in orxonox.OLD for trunk/src/lib/script_engine/script.cc
- Timestamp:
- Jun 14, 2006, 5:50:18 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/script_engine/script.cc
r8271 r8408 23 23 luaopen_math(luaState); 24 24 luaopen_debug(luaState); 25 26 25 if (root != NULL) 27 26 this->loadParams(root); … … 38 37 void Script::loadParams(const TiXmlElement* root) 39 38 { 39 //printf("Loading params for %p \n",this); 40 40 BaseObject::loadParams(root); 41 41 … … 77 77 else 78 78 { 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()); 85 87 reportError(error); 86 88 } … … 92 94 void Script::addObject(const std::string& className, const std::string& objectName) 93 95 { 96 //printf("Script %p: I am about to add %s of class %s\n",this,objectName.c_str(),className.c_str()); 97 94 98 BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS); 99 //printf("The script class for %s is at %p \n",className.c_str(),scriptClass); 95 100 WorldObject tmpObj; 96 101 if (scriptClass != NULL) … … 103 108 104 109 BaseObject* object = ClassList::getObject(objectName, className); 110 //printf("%s is at %p \n",objectName.c_str(),object); 105 111 if (object != NULL && !objectIsAdded(objectName)) 106 112 { … … 162 168 if(error != 0) 163 169 { 170 printf("ERROR while executing function %s: \n",currentFunction.c_str()); 164 171 reportError(error); 172 //clean up 173 currentFunction.assign(""); 174 argumentCount = returnCount = 0; 165 175 return false; 166 176 } … … 174 184 else 175 185 printf("Error: no function selected.\n"); 186 187 return false; 176 188 } 177 189 … … 229 241 int Script::getReturnedInt() 230 242 { 231 int returnValue ;243 int returnValue = 0; 232 244 if(returnCount > 0) 233 245 { 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); 237 250 returnCount--; 238 lua_pop(luaState,1);251 239 252 } 240 253 } … … 245 258 bool Script::getReturnedBool() 246 259 { 247 bool returnValue ;260 bool returnValue = false; 248 261 if(returnCount > 0) 249 262 { 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); 253 267 returnCount--; 254 lua_pop(luaState,1);255 268 } 256 269 } … … 260 273 float Script::getReturnedFloat() 261 274 { 262 float returnValue ;275 float returnValue = 0.0f; 263 276 if(returnCount > 0) 264 277 { 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); 268 282 returnCount--; 269 lua_pop(luaState,1);270 283 } 271 284 } … … 275 288 void Script::getReturnedString(std::string& string) 276 289 { 277 const char* returnValue ;290 const char* returnValue = ""; 278 291 if(returnCount > 0) 279 292 { 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); 283 297 returnCount--; 284 lua_pop(luaState,1);285 298 } 286 299 } … … 296 309 fprintf(stderr, "ERROR: %s\n", msg); 297 310 lua_pop(luaState, 1); 311 } 298 312 return error; 299 313 } 300 }301 314 302 315
Note: See TracChangeset
for help on using the changeset viewer.