Merge branch 'main' into dev

This commit is contained in:
MihailRis 2026-10-10 12:34:29 +03:00
commit 7994d41b19
25 changed files with 142 additions and 76 deletions

View file

@ -1,10 +1,10 @@
project(VoxelEngineSrc)
project(VoxelCoreSrc)
file(GLOB_RECURSE headers ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
add_library(VoxelEngineSrc STATIC ${sources} ${headers})
add_library(VoxelCoreSrc STATIC ${sources} ${headers})
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
@ -70,10 +70,10 @@ else()
add_library(luajit::luajit ALIAS PkgConfig::luajit)
endif()
target_include_directories(VoxelEngineSrc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(VoxelCoreSrc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(
VoxelEngineSrc
VoxelCoreSrc
PRIVATE glfw
OpenGL::GL
GLEW::GLEW
@ -91,7 +91,7 @@ target_link_libraries(
)
target_compile_options(
VoxelEngineSrc
VoxelCoreSrc
PUBLIC $<$<CXX_COMPILER_ID:MSVC>:
/utf-8
/MP
@ -129,7 +129,7 @@ target_compile_options(
>)
target_link_options(
VoxelEngineSrc
VoxelCoreSrc
PUBLIC
$<$<CXX_COMPILER_ID:GNU>:
-no-pie

View file

@ -35,8 +35,15 @@ void InlineFrame::setDocument(const std::shared_ptr<UiDocument>& document) {
root->setSize(size);
gui.postRunnable([this]() {
scripting::on_ui_open(*this->document, {});
gui.postRunnable([weak = weak_from_this(), document]() {
auto node = weak.lock();
if (node == nullptr) {
return;
}
if (static_cast<InlineFrame&>(*node).document != document) {
return;
}
scripting::on_ui_open(*document, {});
});
}

View file

@ -99,14 +99,21 @@ template <typename T, T(tovalueFunc)(lua::State*, int)>
std::function<T()> create_supplier(
const scriptenv& env, const std::string& src, const std::string& file
) {
return [=]() {
return [=, errorLogged = false]() mutable {
lua::stackguard guard(lua::get_main_state());
if (auto L = process_callback(env, src, file)) {
if (lua::isfunction(L, -1)) {
lua::call_nothrow(L, 0);
if (lua::isfunction(L, -1) && !lua::call_nothrow(L, 0)) {
return T {};
}
try {
return tovalueFunc(L, -1);
} catch (const std::exception& err) {
if (!errorLogged) {
logger.error() << "supplier " << util::quote(src) << ": "
<< err.what();
errorLogged = true;
}
}
auto str = tovalueFunc(L, -1);
lua::pop(L);
return str;
}
return T {};
};
@ -158,16 +165,33 @@ int_array_consumer scripting::create_int_array_consumer(
vec2supplier scripting::create_vec2_supplier(
const scriptenv& env, const std::string& src, const std::string& file
) {
return [=]() {
if (auto L = process_callback(env, src, file)) {
if (lua::isfunction(L, -1)) {
lua::call_nothrow(L, 0);
return [=, errorLogged = false]() mutable {
auto L = lua::get_main_state();
lua::stackguard guard(L);
int top = lua::gettop(L);
if (process_callback(env, src, file)) {
if (lua::isfunction(L, -1) && !lua::call_nothrow(L, 0)) {
return glm::vec2(0, 0);
}
if (lua::gettop(L) - top < 2) {
if (!errorLogged) {
logger.error() << "supplier " << util::quote(src)
<< ": two numbers expected";
errorLogged = true;
}
return glm::vec2(0, 0);
}
try {
auto y = lua::tonumber(L, -1);
auto x = lua::tonumber(L, -2);
return glm::vec2(x, y);
} catch (const std::exception& err) {
if (!errorLogged) {
logger.error() << "supplier " << util::quote(src) << ": "
<< err.what();
errorLogged = true;
}
}
auto y = lua::tonumber(L, -1);
lua::pop(L);
auto x = lua::tonumber(L, -1);
lua::pop(L);
return glm::vec2(x, y);
}
return glm::vec2(0, 0);
};