Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 999 for code/branches/script


Ignore:
Timestamp:
Apr 6, 2008, 2:43:12 AM (17 years ago)
Author:
bknecht
Message:

some changes with the script. Made it singleton plus the files were moved into the core.

Location:
code/branches/script
Files:
1 deleted
4 edited
5 moved

Legend:

Unmodified
Added
Removed
  • code/branches/script/cmake/FindLua.cmake

    r998 r999  
    3232
    3333IF (NOT Lua_LIBRARIES)
    34 FIND_LIBRARY(Lua_LIBRARIES lua50 liblua
     34FIND_LIBRARY(Lua_LIBRARIES lua50 lua
    3535        /usr/lib
    3636        /usr/local/lib
    3737        /usr/pack/lua-5.0.3-sd/i686-debian-linux3.1/lib/)
    3838
    39 FIND_LIBRARY(Lua_LIBRARY lualib50 liblualib
     39FIND_LIBRARY(Lua_LIBRARY lualib50 lualib
    4040        /usr/lib
    4141        /usr/local/lib
  • code/branches/script/src/orxonox/CMakeLists.txt

    r996 r999  
    3232  objects/weapon/BulletManager.cc
    3333  objects/weapon/WeaponStation.cc
    34   script/Script.cc
    35   script/tolua_script.cc
    3634)
    3735
     
    4341  ${OGRE_LIBRARIES}
    4442  ${OIS_LIBRARIES}
    45   ${Lua_LIBRARIES}
    46   ${ToLua_LIBRARIES}
    4743  util
    4844  core
  • code/branches/script/src/orxonox/core/CMakeLists.txt

    r919 r999  
    1818  XMLPort.cc
    1919  Tickable.cc
     20  Script.cc
    2021)
    2122
     
    2526TARGET_LINK_LIBRARIES( core
    2627  util
     28  ${Lua_LIBRARIES}
    2729)
  • code/branches/script/src/orxonox/core/Loader.cc

    r996 r999  
    3333#include "Debug.h"
    3434#include "CoreIncludes.h"
    35 #include "../script/Script.h"
     35#include "Script.h"
    3636
    3737#include "util/tinyxml/ticpp.h"
     
    110110        // let Lua work this out:
    111111        //Script* lua;
    112         Script::loadFile(level->getFile(), true);
     112        /*Script::loadFile(level->getFile(), true);
    113113        Script::init(Script::getLuaState());
    114         Script::run();
     114        Script::run();*/
     115        Script* lua = Script::getInstance();
    115116
    116117        try
     
    124125            ticpp::Document xmlfile;
    125126            //xmlfile.ToDocument();
    126             xmlfile.Parse(*Script::getFileString(), true);
     127            xmlfile.Parse(lua->getLuaOutput(), true);
    127128
    128129            for ( ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++ )
  • code/branches/script/src/orxonox/core/Script.cc

    r996 r999  
    3939
    4040#include "tolua++.h"
    41 #include "tolua_script.h"
     41#include "toluabind.h"
    4242
    4343namespace orxonox
    4444{
    4545
    46   lua_State* Script::luaState_ = lua_open();
    47   //lua_State* Script::luaState_ = NULL;
    48   std::string Script::fileString_ = "";
    49 
    5046  Script::Script()
    5147  {
    52   }
    53 
    54   Script::~Script()
    55   {
    56 
    57   }
    58 
    59   /**
    60       @brief Initializes a lua state
    61       @param state_ the pointer of the lua_state to initialise
    62   */
    63   void Script::init(lua_State *state_)
    64   {
    65     tolua_script_open(state_);
    66 
    67     /*
    68 #if LUA_VERSION_NUM == 501
    69     luaL_openlibs(state_);
    70 #else
    71     luaopen_base(state_);
    72     luaopen_table(state_);
    73     luaopen_io(state_);
    74     luaopen_string(state_);
    75     luaopen_math(state_);
    76     luaopen_debug(state_);
    77 #endif
    78     */
     48    luaState_ = lua_open();
     49    luaSource_ = "";
     50    tolua_something_open(luaState_);
    7951  }
    8052
    8153  void Script::luaPrint(std::string str)
    8254  {
    83     fileString_ = str;
     55    output_ = str;
    8456  }
    8557
     
    10072
    10173    char line[1024];
     74    std::string levelString = "";
    10275
    10376    while (file.good() && !file.eof())
    10477    {
    10578      file.getline(line, 1024);
    106       fileString_ += line;
     79      levelString += line;
    10780    }
    10881
     
    11083    //std::string output;
    11184
    112     if (luaTags) fileString_ = replaceLuaTags(Script::fileString_);
     85    if (luaTags) luaSource_ = replaceLuaTags(levelString);
    11386  }
    11487
     
    11790    int error = 0;
    11891    std::string init = "local scr = orxonox.Script:new()\n";
    119     init += fileString_;
     92    init += luaSource_;
    12093    error = luaL_loadstring(luaState_, init.c_str());
    12194    if (error == 0)
  • code/branches/script/src/orxonox/core/Script.h

    r996 r999  
    2121  { // tolua_export
    2222    public:
    23     Script(); // tolua_export
    24     ~Script();
     23      inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; }
     24      inline ~Script() { Script::singletonRef = NULL; };
    2525
    26     static void loadFile(std::string filename, bool luaTags);
    27     static void init(lua_State *state_);
     26    void loadFile(std::string filename, bool luaTags);
     27    //void init(lua_State *state_);
    2828    //void xmlToLua();
    29     static void run();
     29    void run();
    3030    void luaPrint(std::string str); // tolua_export
    3131
    32     inline static lua_State* getLuaState() { return luaState_; };
    33     inline static std::string* getFileString() { return &fileString_; };
     32    inline lua_State* getLuaState() { return luaState_; };
     33    inline std::string getLuaOutput() { return output_; };
     34    //inline std::string* getFileString() { return &fileString_; };
    3435
    35     static unsigned int getNextQuote(const std::string& text, unsigned int start);
    36     static std::string replaceLuaTags(const std::string& text);
     36    unsigned int getNextQuote(const std::string& text, unsigned int start);
     37    std::string replaceLuaTags(const std::string& text);
    3738
    3839    private:
     40      Script();
     41      static Script* singletonRef;
    3942
    40       //std::list<std::string>& getLevelFileLines();
    41 
    42       static std::string fileString_;
    43       static lua_State* luaState_;
     43      std::string luaSource_;
     44      std::string output_;
     45      lua_State* luaState_;
    4446
    4547  }; // tolua_export
Note: See TracChangeset for help on using the changeset viewer.