Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 10, 2008, 4:28:51 PM (16 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
Files:
3 edited
3 moved

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
  • code/branches/script/src/util/tolua/tolua.pkg

    r999 r1019  
    1 $cfile "Script.h"
     1$cfile "../../orxonox/core/Script.h"
  • code/branches/script/src/util/tolua/tolua_bind.cc

    r999 r1019  
    11/*
    2 ** Lua binding: script
    3 ** Generated automatically by tolua++-1.0.92 on Sat Apr  5 20:29:18 2008.
     2** Lua binding: orxonox
     3** Generated automatically by tolua++-1.0.92 on Sun Apr  6 15:44:17 2008.
    44*/
    55
     
    1212
    1313/* Exported function */
    14 TOLUA_API int  tolua_script_open (lua_State* tolua_S);
     14TOLUA_API int  tolua_orxonox_open (lua_State* tolua_S);
    1515
    16 #include "Script.h"
    17 
    18 /* function to release collected object via destructor */
    19 #ifdef __cplusplus
    20 
    21 static int tolua_collect_orxonox__Script (lua_State* tolua_S)
    22 {
    23  orxonox::Script* self = (orxonox::Script*) tolua_tousertype(tolua_S,1,0);
    24         Mtolua_delete(self);
    25         return 0;
    26 }
    27 #endif
    28 
     16#include "../../orxonox/core/Script.h"
    2917
    3018/* function to register type */
     
    3422}
    3523
    36 /* method: new of class  orxonox::Script */
    37 #ifndef TOLUA_DISABLE_tolua_script_orxonox_Script_new00
    38 static int tolua_script_orxonox_Script_new00(lua_State* tolua_S)
     24/* method: getInstance of class  orxonox::Script */
     25#ifndef TOLUA_DISABLE_tolua_orxonox_orxonox_Script_getInstance00
     26static int tolua_orxonox_orxonox_Script_getInstance00(lua_State* tolua_S)
    3927{
    4028#ifndef TOLUA_RELEASE
     
    4937 {
    5038  {
    51    orxonox::Script* tolua_ret = (orxonox::Script*)  Mtolua_new((orxonox::Script)());
     39   orxonox::Script* tolua_ret = (orxonox::Script*)  orxonox::Script::getInstance();
    5240    tolua_pushusertype(tolua_S,(void*)tolua_ret,"orxonox::Script");
    5341  }
     
    5644#ifndef TOLUA_RELEASE
    5745 tolua_lerror:
    58  tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
    59  return 0;
    60 #endif
    61 }
    62 #endif //#ifndef TOLUA_DISABLE
    63 
    64 /* method: new_local of class  orxonox::Script */
    65 #ifndef TOLUA_DISABLE_tolua_script_orxonox_Script_new00_local
    66 static int tolua_script_orxonox_Script_new00_local(lua_State* tolua_S)
    67 {
    68 #ifndef TOLUA_RELEASE
    69  tolua_Error tolua_err;
    70  if (
    71      !tolua_isusertable(tolua_S,1,"orxonox::Script",0,&tolua_err) ||
    72      !tolua_isnoobj(tolua_S,2,&tolua_err)
    73  )
    74   goto tolua_lerror;
    75  else
    76 #endif
    77  {
    78   {
    79    orxonox::Script* tolua_ret = (orxonox::Script*)  Mtolua_new((orxonox::Script)());
    80     tolua_pushusertype(tolua_S,(void*)tolua_ret,"orxonox::Script");
    81     tolua_register_gc(tolua_S,lua_gettop(tolua_S));
    82   }
    83  }
    84  return 1;
    85 #ifndef TOLUA_RELEASE
    86  tolua_lerror:
    87  tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
     46 tolua_error(tolua_S,"#ferror in function 'getInstance'.",&tolua_err);
    8847 return 0;
    8948#endif
     
    9251
    9352/* method: luaPrint of class  orxonox::Script */
    94 #ifndef TOLUA_DISABLE_tolua_script_orxonox_Script_luaPrint00
    95 static int tolua_script_orxonox_Script_luaPrint00(lua_State* tolua_S)
     53#ifndef TOLUA_DISABLE_tolua_orxonox_orxonox_Script_luaPrint00
     54static int tolua_orxonox_orxonox_Script_luaPrint00(lua_State* tolua_S)
    9655{
    9756#ifndef TOLUA_RELEASE
     
    9958 if (
    10059     !tolua_isusertype(tolua_S,1,"orxonox::Script",0,&tolua_err) ||
    101      !tolua_isstring(tolua_S,2,0,&tolua_err) ||
     60     !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
    10261     !tolua_isnoobj(tolua_S,3,&tolua_err)
    10362 )
     
    10766 {
    10867  orxonox::Script* self = (orxonox::Script*)  tolua_tousertype(tolua_S,1,0);
    109   char* str = ((char*)  tolua_tostring(tolua_S,2,0));
     68  std::string str = ((std::string)  tolua_tocppstring(tolua_S,2,0));
    11069#ifndef TOLUA_RELEASE
    11170  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'luaPrint'",NULL);
     
    12584
    12685/* Open function */
    127 TOLUA_API int tolua_script_open (lua_State* tolua_S)
     86TOLUA_API int tolua_orxonox_open (lua_State* tolua_S)
    12887{
    12988 tolua_open(tolua_S);
     
    13392  tolua_module(tolua_S,"orxonox",0);
    13493  tolua_beginmodule(tolua_S,"orxonox");
    135    #ifdef __cplusplus
    136    tolua_cclass(tolua_S,"Script","orxonox::Script","",tolua_collect_orxonox__Script);
    137    #else
    13894   tolua_cclass(tolua_S,"Script","orxonox::Script","",NULL);
    139    #endif
    14095   tolua_beginmodule(tolua_S,"Script");
    141     tolua_function(tolua_S,"new",tolua_script_orxonox_Script_new00);
    142     tolua_function(tolua_S,"new_local",tolua_script_orxonox_Script_new00_local);
    143     tolua_function(tolua_S,".call",tolua_script_orxonox_Script_new00_local);
    144     tolua_function(tolua_S,"luaPrint",tolua_script_orxonox_Script_luaPrint00);
     96    tolua_function(tolua_S,"getInstance",tolua_orxonox_orxonox_Script_getInstance00);
     97    tolua_function(tolua_S,"luaPrint",tolua_orxonox_orxonox_Script_luaPrint00);
    14598   tolua_endmodule(tolua_S);
    14699  tolua_endmodule(tolua_S);
     
    151104
    152105#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
    153  TOLUA_API int luaopen_script (lua_State* tolua_S) {
    154  return tolua_script_open(tolua_S);
     106 TOLUA_API int luaopen_orxonox (lua_State* tolua_S) {
     107 return tolua_orxonox_open(tolua_S);
    155108};
    156109#endif
  • code/branches/script/src/util/tolua/tolua_bind.h

    r999 r1019  
    11/*
    2 ** Lua binding: script
    3 ** Generated automatically by tolua++-1.0.92 on Sat Apr  5 20:29:18 2008.
     2** Lua binding: orxonox
     3** Generated automatically by tolua++-1.0.92 on Sun Apr  6 15:44:17 2008.
    44*/
    55
    66/* Exported function */
    7 TOLUA_API int  tolua_script_open (lua_State* tolua_S);
     7TOLUA_API int  tolua_orxonox_open (lua_State* tolua_S);
    88
Note: See TracChangeset for help on using the changeset viewer.