Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8688


Ignore:
Timestamp:
May 30, 2011, 6:51:00 PM (13 years ago)
Author:
rgrieder
Message:

Removed the need to declare the tolua interface explicitly (DeclareToluaInterface).
This is now automatically done in the ToluaBindLibrary.cc files.
That also removes the need for tolua bind header files.

Location:
code/branches/unity_build
Files:
1 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/unity_build/cmake/tools/GenerateToluaBindings.cmake

    r8650 r8688  
    4949  SET(_tolua_pkgfile "${CMAKE_CURRENT_BINARY_DIR}/tolua.pkg")
    5050  SET(_tolua_cxxfile "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/ToluaBind${_tolua_package}.cc")
    51   SET(_tolua_hfile   "${CMAKE_BINARY_DIR}/src/toluabind/${CMAKE_CFG_INTDIR}/ToluaBind${_tolua_package}.h")
     51  #SET(_tolua_hfile   "${CMAKE_BINARY_DIR}/src/toluabind/${CMAKE_CFG_INTDIR}/ToluaBind${_tolua_package}.h")
    5252
    5353  SET(${_target_source_files}
    5454    ${${_target_source_files}}
    5555    ${_tolua_cxxfile}
    56     ${_tolua_hfile}
    5756    PARENT_SCOPE
    5857  )
     
    7675  ENDFOREACH(_tolua_inputfile)
    7776
     77  IF(TOLUA_PARSER_HOOK_SCRIPT)
     78    # Hook scripts may contain functions that act as Tolua hooks
     79    SET(_hook_script -L "${TOLUA_PARSER_HOOK_SCRIPT}")
     80  ENDIF()
     81
    7882  ADD_CUSTOM_COMMAND(
    79     OUTPUT ${_tolua_cxxfile} ${_tolua_hfile}
     83    OUTPUT ${_tolua_cxxfile}
    8084    COMMAND toluaapp_orxonox -n ${_tolua_package}
    8185                             -w ${CMAKE_CURRENT_SOURCE_DIR}
    8286                             -o ${_tolua_cxxfile}
    83                              -H ${_tolua_hfile}
    8487                             -s ${TOLUA_PARSER_SOURCE}
     88                                ${_hook_script}
    8589                                ${_tolua_pkgfile}
    8690    DEPENDS           ${TOLUA_PARSER_DEPENDENCIES}
  • code/branches/unity_build/src/CMakeLists.txt

    r8644 r8688  
    145145################### Tolua Bind ##################
    146146
    147 # Create directory because the tolua application doesn't work otherwise
    148 IF(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/toluabind/${CMAKE_CFG_INTDIR})
    149   FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/toluabind/${CMAKE_CFG_INTDIR})
    150 ENDIF()
    151 
    152 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/toluabind/${CMAKE_CFG_INTDIR})
     147# Add hook script to the lua code that generates the bindings
     148SET(TOLUA_PARSER_HOOK_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/libraries/core/ToluaInterfaceHook.lua)
     149SET(TOLUA_PARSER_DEPENDENCIES ${TOLUA_PARSER_DEPENDENCIES} ${TOLUA_PARSER_HOOK_SCRIPT})
    153150
    154151################ Sub Directories ################
  • code/branches/unity_build/src/external/tolua/lua/basic.lua

    r5738 r8688  
    354354end
    355355
    356 
     356-- called after all the required C++ includes have been written
     357function post_include_hook(package_name)
     358end
  • code/branches/unity_build/src/external/tolua/lua/package.lua

    r8363 r8688  
    135135        i = i+1
    136136    end
     137
     138    post_include_hook(self.name)
    137139
    138140    output('\n')
  • code/branches/unity_build/src/libraries/core/LuaState.cc

    r8351 r8688  
    4040#include "util/Exception.h"
    4141#include "Resource.h"
    42 #include "ToluaBindCore.h"
    4342#include "command/IOConsole.h"
    4443
    4544namespace orxonox
    4645{
    47     LuaState::ToluaInterfaceMap LuaState::toluaInterfaces_s;
    48     std::vector<LuaState*> LuaState::instances_s;
    49 
    5046    const std::string LuaState::ERROR_HANDLER_NAME = "errorHandler";
    51 
    52     // Do this after declaring toluaInterfaces_s and instances_s to avoid larger problems
    53     DeclareToluaInterface(Core);
    5447
    5548    LuaState::LuaState()
     
    277270    }
    278271
     272    /*static*/ LuaState::ToluaInterfaceMap& LuaState::getToluaInterfaces()
     273    {
     274        static ToluaInterfaceMap p;
     275        return p;
     276    }
     277
     278    /*static*/ std::vector<LuaState*>& LuaState::getInstances()
     279    {
     280        static std::vector<LuaState*> p;
     281        return p;
     282    }
     283
    279284    /*static*/ bool LuaState::addToluaInterface(int (*function)(lua_State*), const std::string& name)
    280285    {
    281         for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
     286        for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it)
    282287        {
    283288            if (it->first == name || it->second == function)
     
    287292            }
    288293        }
    289         toluaInterfaces_s[name] = function;
     294        getToluaInterfaces()[name] = function;
    290295
    291296        // Open interface in all LuaStates
    292         for (std::vector<LuaState*>::const_iterator it = instances_s.begin(); it != instances_s.end(); ++it)
     297        for (std::vector<LuaState*>::const_iterator it = getInstances().begin(); it != getInstances().end(); ++it)
    293298            (*function)((*it)->luaState_);
    294299
     
    299304    /*static*/ bool LuaState::removeToluaInterface(const std::string& name)
    300305    {
    301         ToluaInterfaceMap::iterator it = toluaInterfaces_s.find(name);
    302         if (it == toluaInterfaces_s.end())
     306        ToluaInterfaceMap::iterator it = getToluaInterfaces().find(name);
     307        if (it == getToluaInterfaces().end())
    303308        {
    304309            COUT(2) << "Warning: Cannot remove Tolua interface '" << name << "': Not found" << std::endl;
     
    307312
    308313        // Close interface in all LuaStates
    309         for (std::vector<LuaState*>::const_iterator itState = instances_s.begin(); itState != instances_s.end(); ++itState)
     314        for (std::vector<LuaState*>::const_iterator itState = getInstances().begin(); itState != getInstances().end(); ++itState)
    310315        {
    311316            lua_pushnil((*itState)->luaState_);
     
    314319
    315320        // Remove entry
    316         toluaInterfaces_s.erase(it);
     321        getToluaInterfaces().erase(it);
    317322
    318323        // Return dummy bool
     
    322327    /*static*/ void LuaState::openToluaInterfaces(lua_State* state)
    323328    {
    324         for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
     329        for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it)
    325330            (*it->second)(state);
    326331    }
     
    328333    /*static*/ void LuaState::closeToluaInterfaces(lua_State* state)
    329334    {
    330         for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
     335        for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it)
    331336        {
    332337            lua_pushnil(state);
  • code/branches/unity_build/src/libraries/core/LuaState.h

    r8672 r8688  
    4848#include <vector>
    4949#include <boost/shared_ptr.hpp>
    50 
    51 #include "ToluaInterface.h"
    5250
    5351namespace orxonox // tolua_export
     
    120118
    121119        typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap;
    122         static ToluaInterfaceMap toluaInterfaces_s;
    123         static std::vector<LuaState*> instances_s;
     120        static ToluaInterfaceMap& getToluaInterfaces();
     121        static std::vector<LuaState*>& getInstances();
    124122    }; // tolua_export
     123
     124
     125    //! Helper class that registers/unregisters tolua bindings
     126    class ToluaBindingsHelper
     127    {
     128    public:
     129        ToluaBindingsHelper(int (*function)(lua_State*), const std::string& libraryName)
     130            : libraryName_(libraryName)
     131        {
     132            LuaState::addToluaInterface(function, libraryName_);
     133        }
     134        ~ToluaBindingsHelper()
     135        {
     136            LuaState::removeToluaInterface(libraryName_);
     137        }
     138    private:
     139        std::string libraryName_;
     140    };
    125141} // tolua_export
    126142
  • code/branches/unity_build/src/modules/notifications/NotificationManager.cc

    r8079 r8688  
    4747#include "NotificationQueue.h"
    4848
    49 #include "ToluaBindNotifications.h"
    50 
    5149namespace orxonox
    5250{
     
    5452    const std::string NotificationManager::ALL("all");
    5553    const std::string NotificationManager::NONE("none");
    56 
    57     // Register tolua_open function when loading the library.
    58     DeclareToluaInterface(Notifications);
    5954
    6055    ManageScopedSingleton(NotificationManager, ScopeID::Root, false);
  • code/branches/unity_build/src/modules/pickup/PickupManager.cc

    r7801 r8688  
    4949#include "PickupRepresentation.h"
    5050
    51 #include "ToluaBindPickup.h"
    52 
    5351namespace orxonox
    5452{
    55     // Register tolua_open function when loading the library
    56     DeclareToluaInterface(Pickup);
    57 
    5853    ManageScopedSingleton(PickupManager, ScopeID::Root, false);
    5954
  • code/branches/unity_build/src/modules/questsystem/QuestManager.cc

    r8079 r8688  
    4747#include "QuestItem.h"
    4848
    49 #include "ToluaBindQuestsystem.h"
    50 
    5149namespace orxonox
    5250{
    53     // Register tolua_open function when loading the library
    54     DeclareToluaInterface(Questsystem);
    55 
    5651    ManageScopedSingleton(QuestManager, ScopeID::Root, false);
    5752
  • code/branches/unity_build/src/orxonox/Main.cc

    r7801 r8688  
    3939#include "core/Game.h"
    4040#include "core/LuaState.h"
    41 #include "ToluaBindOrxonox.h"
    42 #include "ToluaBindNetwork.h"
    43 
    44 DeclareToluaInterface(Orxonox);
    45 DeclareToluaInterface(Network);
    4641
    4742namespace orxonox
Note: See TracChangeset for help on using the changeset viewer.