Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jul 17, 2006, 9:29:22 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the branche scripting back here.

merged with command:
svn merge -r9239:HEAD https://svn.orxonox.net/orxonox/branches/scripting .
no conflicts

File:
1 edited

Legend:

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

    r9235 r9298  
    1717#include "script_class.h"
    1818#include "luaincl.h"
    19 
     19#include "debug.h"
    2020#include "util/loading/resource_manager.h"
    2121
     
    5050
    5151
     52Script::Script(const std::string& filename)
     53{
     54  this->setClassID(CL_SCRIPT, "Script");
     55
     56  returnCount = argumentCount = 0;
     57
     58  luaState = lua_open();
     59
     60  luaopen_base(luaState);
     61  luaopen_table(luaState);
     62  luaopen_io(luaState);
     63  luaopen_string(luaState);
     64  luaopen_math(luaState);
     65  luaopen_debug(luaState);
     66 
     67  this->loadFile(filename);
     68
     69}
     70
    5271Script::~Script()
    5372{
     
    5978void Script::loadParams(const TiXmlElement* root)
    6079{
    61   //printf("Loading params for %p \n",this);
     80  //printf(("Loading params for %p \n",this);
    6281  BaseObject::loadParams(root);
    6382
    64   LOAD_PARAM_START_CYCLE(root, object);
     83 LOAD_PARAM_START_CYCLE(root, object);
    6584  {
    6685    LoadParam_CYCLE(object, "object", this, Script, addObject)
    67         .describe("The name of an object that is needed by a script");
     86       .describe("The name of an object that is needed by a script");
    6887  }
    69   LOAD_PARAM_END_CYCLE(object);
     88 LOAD_PARAM_END_CYCLE(object);
    7089
    7190
     
    87106   if(currentFile.length() != 0)
    88107   {
    89      printf("Could not load %s because an other file is already loaded: %s\n",filename.c_str(), currentFile.c_str());
     108     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());
    90109     return false;
    91110    }
     
    104123     else
    105124     {
    106        printf("ERROR while loading file %s: \n",filename.c_str());
     125       printf("SCRIPT %s : ERROR: while loading file %s: \n",currentFile.c_str(),filename.c_str());
    107126       reportError(error);
    108127     }
     
    111130   else
    112131   {
    113      printf("ERROR while loading file %s: \n",filename.c_str());
     132     printf("SCRIPT %s : ERROR: while loading file %s: \n",currentFile.c_str(),filename.c_str());
    114133     reportError(error);
    115134   }
     
    121140 void Script::addObject(const std::string& className, const std::string& objectName)
    122141 {
    123    //printf("Script %s: I am about to add %s of class %s\n",this->getName(),objectName.c_str(),className.c_str());
     142   //printf(("Script %s: I am about to add %s of class %s\n",this->getName(),objectName.c_str(),className.c_str());
    124143
    125144   BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
    126   // printf("The script class for %s is at %p \n",className.c_str(),scriptClass);
     145  // printf(("The script class for %s is at %p \n",className.c_str(),scriptClass);
    127146   WorldObject tmpObj;
    128147   if (scriptClass != NULL)
     
    135154
    136155     BaseObject* object = ClassList::getObject(objectName, className);
    137     // printf("%s is at %p \n",objectName.c_str(),object);
     156    // printf(("%s is at %p \n",objectName.c_str(),object);
    138157     if (object != NULL && !objectIsAdded(objectName))
    139158     {
     
    150169 bool Script::executeFile()
    151170 {
    152    printf("WARNING: script.executeFile is not implemented yet");
     171   PRINT(2)("WARNING: script.executeFile is not implemented yet\n");
    153172   /*if(currentFile.length() != 0)
    154173   {
     
    183202   }
    184203   else
    185      printf("There is an other function active ( %s ) or there are unremoved return values on the stack. Please remove them first.\n",currentFunction.c_str());
     204     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());
    186205   return false;
    187206 }
     
    195214    if(error != 0)
    196215    {
    197      printf("ERROR while executing function %s: \n",currentFunction.c_str());
     216      printf("SCRIPT %s : ERROR: Failed to execute function %s: \n",currentFile.c_str(),currentFunction.c_str());
    198217     reportError(error);
    199218     //clean up
     
    210229   }
    211230   else
    212      printf("Error: no function selected.\n");
     231     printf("SCRIPT %s : ERROR: no function selected.\n",currentFile.c_str());
    213232
    214233   return false;
     
    227246   else
    228247   {
    229     printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
     248     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());
    230249    return false;
    231250   }
     
    244263   else
    245264   {
    246      printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
     265     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());
    247266     return false;
    248267   }
     
    260279   else
    261280   {
    262      printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
     281     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());
    263282     return false;
    264283   }
     
    295314     }
    296315     else
    297        printf("ERROR: Form %s : trying to retreive non bolean value",this->currentFile.c_str());
     316       printf("SCRIPT %s : ERROR: Trying to retreive non bolean value\n",this->currentFile.c_str());
    298317   }
    299318   return returnValue;
     
    346365 {
    347366  const char *msg = lua_tostring(luaState, -1);
    348   if (msg == NULL) msg = "(error with no message)";
    349   fprintf(stderr, "ERROR: %s\n", msg);
     367  if (msg == NULL) msg = "(error with no message)\n";
     368  printf("ERROR: %s\n", msg);
    350369  lua_pop(luaState, 1);
    351370 }
     
    368387 {
    369388   BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
    370    //printf("The script class for %s is at %p \n",className.c_str(),scriptClass);
     389   //printf(("The script class for %s is at %p \n",className.c_str(),scriptClass);
    371390   WorldObject tmpObj;
    372391   if (scriptClass != NULL)
Note: See TracChangeset for help on using the changeset viewer.