using sol in code

This commit is contained in:
devZoGok
2023-09-02 18:31:11 +03:00
parent 53934504a7
commit aba7c30b08
5 changed files with 20 additions and 18 deletions
+1 -1
View File
@@ -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)
+6 -15
View File
@@ -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<string>{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<Index>{idIndex, Index("bind")});
Mapping::BindType type = (Mapping::BindType)luaManager->getIntFromTable(table, vector<Index>{idIndex, Index("bindType")});
bool action = luaManager->getBoolFromTable(table, vector<Index>{idIndex, Index("action")});
int trigger = luaManager->getIntFromTable(table, vector<Index>{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);
}
}
View File
+11
View File
@@ -0,0 +1,11 @@
#ifndef SOL_UTIL_H
#define SOL_UTIL_H
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>
namespace gameBase{
static sol::state sol, &SOL_LUA_STATE = sol;
}
#endif
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef UTILS_H
#define UTILS_H
#ifndef GAME_BASE_UTIL_H
#define GAME_BASE_UTIL_H
#include <vector>
#include <fstream>