generating sol views from one static lua state

This commit is contained in:
devZoGok
2023-09-03 09:01:49 +03:00
parent aba7c30b08
commit 3f0a70a681
5 changed files with 32 additions and 3 deletions
+1 -1
View File
@@ -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})
+3 -1
View File
@@ -1,6 +1,7 @@
#include <sol/sol.hpp>
#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";
+5
View File
@@ -2,10 +2,15 @@
#define ABSTRACT_APP_STATE_H
#include "mapping.h"
#include "solUtil.h"
#include <string>
#include <vector>
namespace sol{
class state;
}
namespace gameBase {
class AbstractAppState{
public:
+16
View File
@@ -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;
}
}
+7 -1
View File
@@ -4,8 +4,14 @@
#include <sol/sol.hpp>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
namespace gameBase{
static sol::state sol, &SOL_LUA_STATE = sol;
sol::state_view generateView();
}
#endif