diff --git a/CMakeLists.txt b/CMakeLists.txt index a2d2821..933bedb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,6 @@ target_include_directories(${LIB_NAME} PUBLIC ${LUA_DIR}/external/upstream) set(SOL_DIR external/sol2) add_subdirectory(${SOL_DIR}) -target_include_directories(${LIB_NAME} PUBLIC ${SOL_DIR}/include/sol) +target_include_directories(${LIB_NAME} PUBLIC ${SOL_DIR}/include) target_link_libraries(${LIB_NAME} glfw lua::lib) diff --git a/abstractAppState.cpp b/abstractAppState.cpp index 23a09d0..97ec8cb 100644 --- a/abstractAppState.cpp +++ b/abstractAppState.cpp @@ -1,13 +1,11 @@ #include "abstractAppState.h" #include "util.h" +#include "solUtil.h" #include "mapping.h" -#include "luaManager.h" namespace gameBase { using namespace std; - typedef LuaManager::Index Index; - AbstractAppState::AbstractAppState(int type, int firstMapping, int numMappings, string optionsFile){ this->type = type; this->firstMapping = firstMapping; @@ -18,22 +16,15 @@ namespace gameBase { void AbstractAppState::onAttached(){ attached = true; - LuaManager *luaManager = LuaManager::getSingleton(); - luaManager->buildScript(vector{optionsFile}); + SOL_LUA_STATE.script_file(optionsFile); string table = "mappings"; for(int i = firstMapping; i < firstMapping + numMappings; i++){ - Index idIndex = Index(i + 1); - int bind = luaManager->getIntFromTable(table, vector{idIndex, Index("bind")}); - Mapping::BindType type = (Mapping::BindType)luaManager->getIntFromTable(table, vector{idIndex, Index("bindType")}); - bool action = luaManager->getBoolFromTable(table, vector{idIndex, Index("action")}); - int trigger = luaManager->getIntFromTable(table, vector{idIndex, Index("trigger")}); - Mapping *m = new Mapping; - m->bind = bind; - m->type = type; - m->action = action; - m->trigger = trigger; + m->bind = SOL_LUA_STATE[table][i + 1]["bind"]; + m->type = (Mapping::BindType)SOL_LUA_STATE[table][i + 1]["bindType"]; + m->action = SOL_LUA_STATE[table][i + 1]["action"]; + m->trigger = SOL_LUA_STATE[table][i + 1]["trigger"]; mappings.push_back(m); } } diff --git a/solUtil.cpp b/solUtil.cpp new file mode 100644 index 0000000..e69de29 diff --git a/solUtil.h b/solUtil.h new file mode 100644 index 0000000..a5f660c --- /dev/null +++ b/solUtil.h @@ -0,0 +1,11 @@ +#ifndef SOL_UTIL_H +#define SOL_UTIL_H +#define SOL_ALL_SAFETIES_ON 1 + +#include + +namespace gameBase{ + static sol::state sol, &SOL_LUA_STATE = sol; +} + +#endif diff --git a/util.h b/util.h index 50c1e32..39394a8 100644 --- a/util.h +++ b/util.h @@ -1,5 +1,5 @@ -#ifndef UTILS_H -#define UTILS_H +#ifndef GAME_BASE_UTIL_H +#define GAME_BASE_UTIL_H #include #include