Кооректировка подключения Lua
This commit is contained in:
@@ -91,6 +91,8 @@ FetchContent_Declare(
|
||||
)
|
||||
FetchContent_MakeAvailable(luajit)
|
||||
|
||||
set(LUAJIT_DIR ${luajit_SOURCE_DIR})
|
||||
set(LUAJIT_ENABLE_LUA52COMPAT ON)
|
||||
FetchContent_Declare(
|
||||
lua_cmake
|
||||
GIT_REPOSITORY https://github.com/zhaozg/luajit-cmake.git
|
||||
@@ -98,11 +100,20 @@ FetchContent_Declare(
|
||||
GIT_PROGRESS true
|
||||
USES_TERMINAL_DOWNLOAD true
|
||||
)
|
||||
set(LUAJIT_DIR ${luajit_SOURCE_DIR})
|
||||
FetchContent_MakeAvailable(lua_cmake)
|
||||
|
||||
target_link_libraries(luavox_common INTERFACE luajit::lib luajit::header)
|
||||
target_link_libraries(luavox_common INTERFACE luajit::header luajit::lib)
|
||||
target_include_directories(luavox_common INTERFACE ${lua_cmake_BINARY_DIR})
|
||||
|
||||
FetchContent_Declare(
|
||||
sol2
|
||||
GIT_REPOSITORY https://github.com/ThePhD/sol2.git
|
||||
GIT_TAG v3.5.0
|
||||
GIT_PROGRESS true
|
||||
USES_TERMINAL_DOWNLOAD true
|
||||
)
|
||||
FetchContent_MakeAvailable(sol2)
|
||||
target_link_libraries(luavox_common INTERFACE sol2::sol2)
|
||||
|
||||
|
||||
FetchContent_Declare(
|
||||
|
||||
@@ -25,14 +25,12 @@
|
||||
#include "glm/gtc/noise.hpp"
|
||||
#include <fstream>
|
||||
|
||||
extern "C" {
|
||||
#include "lauxlib.h"
|
||||
#include "lua.h"
|
||||
}
|
||||
#define SOL_ALL_SAFETIES_ON 1
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
namespace js = boost::json;
|
||||
|
||||
int luaPanic(lua_State *L)
|
||||
int luaPanic(lua_State* L)
|
||||
{
|
||||
size_t length;
|
||||
const char *str = luaL_checklstring(L, -1, &length);
|
||||
@@ -41,6 +39,12 @@ int luaPanic(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luaAtException(lua_State* L, sol::optional<const std::exception&> exc, std::string_view view) {
|
||||
MAKE_ERROR("LUA EXCEPTION: unprotected error in call to Lua API (" << view << ")");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace LV::Server {
|
||||
|
||||
GameServer::GameServer(asio::io_context &ioc, fs::path worldPath)
|
||||
@@ -69,9 +73,14 @@ GameServer::GameServer(asio::io_context &ioc, fs::path worldPath)
|
||||
// Тест луа
|
||||
|
||||
|
||||
lua_State *m_luastack = luaL_newstate();
|
||||
lua_atpanic(m_luastack, &luaPanic);
|
||||
|
||||
// lua_State *m_luastack = luaL_newstate();
|
||||
// lua_atpanic(m_luastack, &luaPanic);
|
||||
|
||||
sol::state lua;
|
||||
// lua.set_panic(luaPanic);
|
||||
lua.set_exception_handler(luaAtException);
|
||||
lua.script("test = \"Hello world!\" print(test) fast = test..test");
|
||||
LOG.debug() << std::string(lua["fast"]);
|
||||
}
|
||||
|
||||
GameServer::~GameServer() {
|
||||
|
||||
Reference in New Issue
Block a user