Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8231 in orxonox.OLD for branches/script_engine


Ignore:
Timestamp:
Jun 8, 2006, 12:21:21 PM (18 years ago)
Author:
snellen
Message:

Prepared tests

Location:
branches/script_engine/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/defs/class_id.h

    r8193 r8231  
    217217  // Testing Entities
    218218  CL_TEST_ENTITY                =    0x00000409,
     219  CL_ACCOUNT                    =    0x00000410,
     220  CL_TEST_OBJECT                =    0x00000411,
    219221
    220222  // misc
     
    236238  CL_AMMO_CONTAINER             =    0x00000604,
    237239  CL_HUD                        =    0x00000620,
    238  
    239  
     240
     241
    240242  CL_SCRIPT_MANAGER             =    0x00000650,
    241243  CL_SCRIPT                     =    0x00000651,
  • branches/script_engine/src/lib/script_engine/example.cc

    r8128 r8231  
    66#include "script.h"
    77
     8// create classdummys for the scripts
     9CREATE_SCRIPTABLE_CLASS(Account, CL_ACCOUNT)
     10CREATE_SCRIPTABLE_CLASS(Object, CL_TEST_OBJECT)
    811
    912    class Account : public BaseObject {
     
    8184    int main(int argc, char *argv[])
    8285    {
    83       Script script;
    84       printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
     86      std::string file("lunartest2.lua");
     87     // Script script;
     88      Script* script = ScriptManager::getInstance()->getScriptByFile(file);
     89      printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState()));
    8590
    8691      // Register classes with the script
    87       Lunar<Account>::Register(&script);
    88       Lunar<Object>::Register(&script);
     92      // Lunar<Account>::Register(&script);
     93      //Lunar<Object>::Register(&script);
    8994
    90       Object* obj= new Object();
    91       Account a;
    92       Account *b = new Account(30);
     95      //Object* obj= new Object();
     96      //Account a;
     97      //Account *b = new Account(30);
    9398
    9499      // Add instances to the script
    95       Lunar<Object>::insertObject(&script,obj,"Obj",true);
    96       Lunar<Account>::insertObject(&script,&a,"a",false);
    97       Lunar<Account>::insertObject(&script,b,"b",true);
    98        printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
     100      //Lunar<Object>::insertObject(&script,obj,"Obj",true);
     101      //Lunar<Account>::insertObject(&script,&a,"a",false);
     102      //Lunar<Account>::insertObject(&script,b,"b",true);
     103       //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
    99104
    100105      //Load a file
    101       std::string file(argv[1]);
     106      //std::string file("lunartest2.lua");
    102107
    103       if(script.loadFile(file))
    104         printf("File %s succefully loaded\n", file.c_str());
    105       printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
     108      //if(script.loadFile(file))
     109        //printf("File %s succefully loaded\n", file.c_str());
     110      //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
    106111
    107112      //execute a function
    108113      printf("----------- main -----------\n");
    109114      std::string main("main");
    110       if( script.selectFunction(main,3))
     115      if( script->selectFunction(main,3))
    111116       printf("function %s selected\n",main.c_str());
    112117
    113       script.pushParam(3.14159,main);
    114       script.executeFunction();
     118      script->pushParam(3.14159,main);
     119      script->executeFunction();
    115120
    116       float retf = script.getReturnedFloat();
     121      float retf = script->getReturnedFloat();
    117122      printf("main returned %f\n",retf);
    118123
    119124
    120       if(script.getReturnedBool())
     125      if(script->getReturnedBool())
    121126       printf("main returned true\n");
    122127      else
    123128       printf("main returned false\n");
    124129
    125       int ret = script.getReturnedInt();
     130      int ret = script->getReturnedInt();
    126131      printf("main returned %i\n",ret);
    127132
    128       printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
     133      //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
    129134      //execute a 2nd function
    130135      printf("----------- test -----------\n");
    131136      std::string test("test");
    132       if( script.selectFunction(test,0))
     137      if( script->selectFunction(test,0))
    133138       printf("function %s selected\n",test.c_str());
    134139
    135       script.executeFunction();
     140      script->executeFunction();
    136141
    137142
    138143      //if(argc>1) lua_dofile(script.getLuaState(), argv[1]);
    139       printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
     144      printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState()));
    140145
    141146      return 0;
  • branches/script_engine/src/lib/script_engine/script.cc

    r8207 r8231  
    1212{
    1313  this->setClassID(CL_SCRIPT, "Script");
    14  
     14
    1515  returnCount = argumentCount = 0;
    1616
     
    2323  luaopen_math(luaState);
    2424  luaopen_debug(luaState);
    25  
     25
    2626  if (root != NULL)
    2727    this->loadParams(root);
     
    3939{
    4040  BaseObject::loadParams(root);
    41  
     41
    4242  LOAD_PARAM_START_CYCLE(root, object);
    4343  {
     
    8989 }
    9090
    91  
     91
    9292 void Script::addObject(const std::string& className, const std::string& objectName)
    9393 {
     
    9696   if (scriptClass != NULL)
    9797   {
     98     tmpObj.type = className;
    9899     if( !classIsRegistered(className) )
    99100     {
    100101     static_cast<ScriptClass*>(scriptClass)->registerClass(this);
    101      tmpObj.type = className;
    102      }
    103      
     102     }
     103
    104104     BaseObject* object = ClassList::getObject(objectName, className);
    105105     if (object != NULL && !objectIsAdded(objectName))
     
    112112 }
    113113
    114  
    115  
    116  
     114
     115
     116
    117117 bool Script::executeFile()
    118118 {
    119    if(currentFile.length() != 0)
     119   printf("WARNING: script.executeFile is not implemented yet");
     120   /*if(currentFile.length() != 0)
    120121   {
    121122    int error = lua_pcall(luaState, 0, 0, 0);
     
    127128       return false;
    128129      }
    129    }
     130 }*/
    130131   return false;
    131132 }
     
    299300 }
    300301
    301  
     302
    302303 bool Script::classIsRegistered(const std::string& type)
    303304 {
     
    311312   return false;
    312313 }
    313  
    314  
    315  
     314
     315
     316
    316317 bool Script::objectIsAdded(const std::string& name)
    317318 {
     
    324325   }
    325326   return false;
    326  
    327  
    328  }
     327
     328
     329 }
Note: See TracChangeset for help on using the changeset viewer.