Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 23, 2009, 8:47:55 PM (15 years ago)
Author:
rgrieder
Message:

Generalised use of tolua interfaces a bit: GSRoot now adds the interface functions to LuaBind which supports two new functions: openToluaInterfaces and closeToluaInterfaces. Both accept a lua state and can therefore be used to inject our own tolua bindings (the GUIManager makes use of that).
There's also something new: When loading a level, you could now use the tolua bindings from Orxonox as well (not just those from Core).

Location:
code/branches/resource/src/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource/src/core/LuaBind.cc

    r3301 r3340  
    3939#include "util/Debug.h"
    4040#include "util/StringUtils.h"
    41 #include "ToluaBindCore.h"
    4241#include "Core.h"
    4342
     
    6564    luaopen_debug(luaState_);
    6665#endif
    67     tolua_Core_open(luaState_);
     66
     67    // Open all available tolua interfaces
     68    this->openToluaInterfaces(luaState_);
     69
    6870    output_ = "";
    6971    isRunning_ = false;
    7072  }
     73
     74  LuaBind::~LuaBind()
     75  {
     76    this->closeToluaInterfaces(luaState_);
     77
     78    assert(singletonRef_s);
     79    LuaBind::singletonRef_s = NULL;
     80  };
    7181
    7282  void LuaBind::luaPrint(const std::string& str)
     
    315325  }
    316326
     327  void LuaBind::addToluaInterface(int (*function)(lua_State*), const std::string& name)
     328  {
     329    toluaInterfaces_.push_back(std::make_pair(name, function));
     330    // Apply changes to our own lua state as well
     331    (*function)(luaState_);
     332  }
     333
     334  void LuaBind::openToluaInterfaces(lua_State* state)
     335  {
     336    for (unsigned int i = 0; i < toluaInterfaces_.size(); ++i)
     337      (*toluaInterfaces_[i].second)(state);
     338  }
     339
     340  void LuaBind::closeToluaInterfaces(lua_State* state)
     341  {
     342    for (unsigned int i = 0; i < toluaInterfaces_.size(); ++i)
     343    {
     344      lua_pushnil(state);
     345      lua_setglobal(state, toluaInterfaces_[i].first.c_str());
     346    }
     347  }
     348
    317349}
  • code/branches/resource/src/core/LuaBind.h

    r3196 r3340  
    5858    public:
    5959      LuaBind();
    60       inline ~LuaBind() { assert(singletonRef_s); LuaBind::singletonRef_s = NULL; };
     60      ~LuaBind();
    6161
    6262      inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export
     
    8383        { this->includePath_ = includepath; }
    8484
     85    void addToluaInterface(int (*function)(lua_State*), const std::string& name);
     86    void openToluaInterfaces(lua_State* state);
     87    void closeToluaInterfaces(lua_State* state);
     88
    8589    private:
    8690      static LuaBind* singletonRef_s;
     
    9195      bool isRunning_;
    9296      std::string includePath_;
     97      std::vector<std::pair<std::string, int (*)(lua_State *L)> > toluaInterfaces_;
    9398
    9499  }; // tolua_export
Note: See TracChangeset for help on using the changeset viewer.