diff --git a/CMakeLists.txt b/CMakeLists.txt index 933bedb..ba3646b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(states abstractAppState.cpp) set(core inputManager.cpp mapping.h stateManager.cpp) -set(util util.cpp) +set(util solUtil.cpp util.cpp) set(LIB_NAME gameBase) add_library(${LIB_NAME} STATIC ${states} ${core} ${util}) diff --git a/abstractAppState.cpp b/abstractAppState.cpp index 97ec8cb..3d67521 100644 --- a/abstractAppState.cpp +++ b/abstractAppState.cpp @@ -1,6 +1,7 @@ +#include + #include "abstractAppState.h" #include "util.h" -#include "solUtil.h" #include "mapping.h" namespace gameBase { @@ -16,6 +17,7 @@ namespace gameBase { void AbstractAppState::onAttached(){ attached = true; + sol::state_view SOL_LUA_STATE = generateView(); SOL_LUA_STATE.script_file(optionsFile); string table = "mappings"; diff --git a/abstractAppState.h b/abstractAppState.h index 9a8d3fd..d08c71e 100644 --- a/abstractAppState.h +++ b/abstractAppState.h @@ -2,10 +2,15 @@ #define ABSTRACT_APP_STATE_H #include "mapping.h" +#include "solUtil.h" #include #include +namespace sol{ + class state; +} + namespace gameBase { class AbstractAppState{ public: diff --git a/solUtil.cpp b/solUtil.cpp index e69de29..3993562 100644 --- a/solUtil.cpp +++ b/solUtil.cpp @@ -0,0 +1,16 @@ +#include "solUtil.h" + +namespace gameBase{ + static lua_State *state = nullptr; + + sol::state_view generateView(){ + if(!state){ + state = luaL_newstate(); + luaL_openlibs(state); + } + + sol::state_view view(state); + return view; + } +} + diff --git a/solUtil.h b/solUtil.h index a5f660c..e02682a 100644 --- a/solUtil.h +++ b/solUtil.h @@ -4,8 +4,14 @@ #include +extern "C" { + #include + #include + #include +} + namespace gameBase{ - static sol::state sol, &SOL_LUA_STATE = sol; + sol::state_view generateView(); } #endif