Кооректировка подключения Lua

This commit is contained in:
2025-07-28 17:26:03 +06:00
parent a53c2be381
commit fbe48124a6
2 changed files with 30 additions and 10 deletions

View File

@@ -91,6 +91,8 @@ FetchContent_Declare(
) )
FetchContent_MakeAvailable(luajit) FetchContent_MakeAvailable(luajit)
set(LUAJIT_DIR ${luajit_SOURCE_DIR})
set(LUAJIT_ENABLE_LUA52COMPAT ON)
FetchContent_Declare( FetchContent_Declare(
lua_cmake lua_cmake
GIT_REPOSITORY https://github.com/zhaozg/luajit-cmake.git GIT_REPOSITORY https://github.com/zhaozg/luajit-cmake.git
@@ -98,11 +100,20 @@ FetchContent_Declare(
GIT_PROGRESS true GIT_PROGRESS true
USES_TERMINAL_DOWNLOAD true USES_TERMINAL_DOWNLOAD true
) )
set(LUAJIT_DIR ${luajit_SOURCE_DIR})
FetchContent_MakeAvailable(lua_cmake) 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( FetchContent_Declare(

View File

@@ -25,10 +25,8 @@
#include "glm/gtc/noise.hpp" #include "glm/gtc/noise.hpp"
#include <fstream> #include <fstream>
extern "C" { #define SOL_ALL_SAFETIES_ON 1
#include "lauxlib.h" #include <sol/sol.hpp>
#include "lua.h"
}
namespace js = boost::json; namespace js = boost::json;
@@ -41,6 +39,12 @@ int luaPanic(lua_State *L)
return 0; 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 { namespace LV::Server {
GameServer::GameServer(asio::io_context &ioc, fs::path worldPath) 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_State *m_luastack = luaL_newstate();
lua_atpanic(m_luastack, &luaPanic); // 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() { GameServer::~GameServer() {