mirror of
https://github.com/devZoGok/gameBase.git
synced 2026-08-26 19:43:28 +00:00
using sol in code
This commit is contained in:
+1
-1
@@ -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
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user