Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 10, 2008, 4:28:51 PM (17 years ago)
Author:
bknecht
Message:

You can now use lua tags everywhere in the XML file you want: It'll work. Even wrongly put tags are corrected now. Read the wikipages about scripting to see how you can use it.

Location:
code/branches/script/src/orxonox/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/script/src/orxonox/core/Loader.cc

    r999 r1019  
    114114        Script::run();*/
    115115        Script* lua = Script::getInstance();
     116        lua->loadFile(level->getFile(), true);
     117        lua->run();
    116118
    117119        try
  • code/branches/script/src/orxonox/core/Script.cc

    r999 r1019  
    3939
    4040#include "tolua++.h"
    41 #include "toluabind.h"
     41#include "../../util/tolua/tolua_bind.h"
    4242
    4343namespace orxonox
    4444{
     45  Script* Script::singletonRef = NULL;
    4546
    4647  Script::Script()
     
    4849    luaState_ = lua_open();
    4950    luaSource_ = "";
    50     tolua_something_open(luaState_);
     51    luaL_openlibs(luaState_);
     52    tolua_orxonox_open(luaState_);
     53    output_;
    5154  }
    5255
    5356  void Script::luaPrint(std::string str)
    5457  {
    55     output_ = str;
     58    output_ += str;
     59    COUT(0) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl;
    5660  }
    5761
     
    7882      file.getline(line, 1024);
    7983      levelString += line;
     84      levelString += "\n";
    8085    }
    8186
     
    8489
    8590    if (luaTags) luaSource_ = replaceLuaTags(levelString);
     91    COUT(0) << "ParsedSourceCode: " << luaSource_ << std::endl;
    8692  }
    8793
     
    8995  {
    9096    int error = 0;
    91     std::string init = "local scr = orxonox.Script:new()\n";
     97    std::string init = "local scr = orxonox.Script:getInstance()\nprint = function(s)\nscr:luaPrint(s)\nend\n";
    9298    init += luaSource_;
    9399    error = luaL_loadstring(luaState_, init.c_str());
     
    135141    {
    136142      std::map<unsigned int, bool>::iterator it = luaTags.begin();
     143      std::map<unsigned int, bool>::iterator it2 = it;
    137144      bool bBetweenQuotes = false;
     145      bool bBetweenTags = false;
    138146      unsigned int pos = 0;
    139147      while ((pos = getNextQuote(text, pos)) != std::string::npos)
    140148      {
    141         while ((it != luaTags.end()) && ((*it).first < pos))
    142         {
    143           if (bBetweenQuotes)
    144             luaTags.erase(it++);
     149        while ((it != luaTags.end()) && (it->first < pos))
     150        {
     151          if (bBetweenQuotes) {
     152            it2++;
     153            if(it->second && !(it2->second) && it2->first < pos)
     154              it = ++it2;
     155            else
     156              luaTags.erase(it++);
     157          }
    145158          else
    146159            ++it;
     
    233246            equalSigns += "=";
    234247          }
    235           output += "scr:luaPrint([" + equalSigns + "[" + temp + "]" + equalSigns +"])\n";
     248          output += "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])";
    236249          start = end + 5;
    237250        }
  • code/branches/script/src/orxonox/core/Script.h

    r999 r1019  
    2121  { // tolua_export
    2222    public:
    23       inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; }
     23      inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; } // tolua_export
    2424      inline ~Script() { Script::singletonRef = NULL; };
    2525
Note: See TracChangeset for help on using the changeset viewer.