From 126a8485a1250cb8bf7412a8e1b9032cd7fa326d Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 7 Jan 2026 20:03:34 +0300 Subject: [PATCH] remove content-related functions from core library --- res/scripts/stdlib.lua | 14 +++--- src/logic/scripting/lua/libs/libapp.cpp | 61 ++++++++++++++++++++++++ src/logic/scripting/lua/libs/libcore.cpp | 60 ----------------------- 3 files changed, 67 insertions(+), 68 deletions(-) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 06ba4f6e8..cc0131fa7 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -27,14 +27,12 @@ end local __vc__app_script_coroutine local function complete_app_lib(app) - local __core_load_content = core.load_content - local __core_reset_content = core.reset_content - local __core_reconfig_packs = core.reconfig_packs + local __app_load_content = app.load_content + local __app_reset_content = app.reset_content + local __app_reconfig_packs = app.reconfig_packs local __app_tick = coroutine.yield local __app_set_setting = app.set_setting local __app_quit = app.quit - core.load_content = nil - core.reset_content = nil app.sleep = sleep app.script = __VC_SCRIPT_NAME @@ -61,13 +59,13 @@ local function complete_app_lib(app) end app.reconfig_packs = function(...) - call_in_app_script_co(__core_reconfig_packs, ...) + call_in_app_script_co(__app_reconfig_packs, ...) end app.load_content = function(...) - call_in_app_script_co(__core_load_content, ...) + call_in_app_script_co(__app_load_content, ...) end app.reset_content = function(...) - call_in_app_script_co(__core_reset_content, ...) + call_in_app_script_co(__app_reset_content, ...) end function app.config_packs(packs_list) diff --git a/src/logic/scripting/lua/libs/libapp.cpp b/src/logic/scripting/lua/libs/libapp.cpp index b949adf72..9412baa36 100644 --- a/src/logic/scripting/lua/libs/libapp.cpp +++ b/src/logic/scripting/lua/libs/libapp.cpp @@ -4,6 +4,7 @@ #include "io/settings_io.hpp" #include "io/devices/MemoryDevice.hpp" #include "logic/scripting/scripting.hpp" +#include "logic/EngineController.hpp" #include "content/ContentControl.hpp" #include "engine/Engine.hpp" #include "engine/EnginePaths.hpp" @@ -29,6 +30,63 @@ static int l_is_content_loaded(lua::State* L) { return lua::pushboolean(L, content != nullptr); } +static int l_load_content(lua::State* L) { + content_control->loadContent(); + return 0; +} + +static int l_reset_content(lua::State* L) { + if (level != nullptr) { + throw std::runtime_error("world must be closed before"); + } + std::vector nonResetPacks; + if (lua::istable(L, 1)) { + int len = lua::objlen(L, 1); + for (int i = 0; i < len; i++) { + lua::rawgeti(L, i + 1, 1); + nonResetPacks.emplace_back(lua::require_lstring(L, -1)); + lua::pop(L); + } + } + content_control->resetContent(std::move(nonResetPacks)); + return 0; +} + +/// @brief Reconfigure packs +/// @param addPacks An array of packs to add +/// @param remPacks An array of packs to remove +static int l_reconfig_packs(lua::State* L) { + if (!lua::istable(L, 1)) { + throw std::runtime_error("strings array expected as the first argument"); + } + if (!lua::istable(L, 2)) { + throw std::runtime_error("strings array expected as the second argument"); + } + std::vector addPacks; + int addLen = lua::objlen(L, 1); + for (int i = 0; i < addLen; i++) { + lua::rawgeti(L, i + 1, 1); + addPacks.emplace_back(lua::require_lstring(L, -1)); + lua::pop(L); + } + std::vector remPacks; + int remLen = lua::objlen(L, 2); + for (int i = 0; i < remLen; i++) { + lua::rawgeti(L, i + 1, 2); + remPacks.emplace_back(lua::require_lstring(L, -1)); + lua::pop(L); + } + auto engineController = engine->getController(); + try { + engineController->reconfigPacks(controller, addPacks, remPacks); + } catch (const contentpack_error& err) { + throw std::runtime_error( + std::string(err.what()) + " [" + err.getPackId() + " ]" + ); + } + return 0; +} + static int l_start_debug_instance(lua::State* L) { if (!engine->getProject().permissions.has(Permissions::DEBUGGING)) { throw std::runtime_error("project has no debugging permission"); @@ -217,6 +275,9 @@ static int l_quit(lua::State*) { const luaL_Reg applib[] = { {"get_version", lua::wrap}, {"is_content_loaded", lua::wrap}, + {"load_content", lua::wrap}, + {"reset_content", lua::wrap}, + {"reconfig_packs", lua::wrap}, {"start_debug_instance", lua::wrap}, {"focus", lua::wrap}, {"create_memory_device", lua::wrap}, diff --git a/src/logic/scripting/lua/libs/libcore.cpp b/src/logic/scripting/lua/libs/libcore.cpp index 71a38d192..b9648ad35 100644 --- a/src/logic/scripting/lua/libs/libcore.cpp +++ b/src/logic/scripting/lua/libs/libcore.cpp @@ -23,28 +23,6 @@ using namespace scripting; -static int l_load_content(lua::State* L) { - content_control->loadContent(); - return 0; -} - -static int l_reset_content(lua::State* L) { - if (level != nullptr) { - throw std::runtime_error("world must be closed before"); - } - std::vector nonResetPacks; - if (lua::istable(L, 1)) { - int len = lua::objlen(L, 1); - for (int i = 0; i < len; i++) { - lua::rawgeti(L, i + 1, 1); - nonResetPacks.emplace_back(lua::require_lstring(L, -1)); - lua::pop(L); - } - } - content_control->resetContent(std::move(nonResetPacks)); - return 0; -} - /// @brief Creating new world /// @param name Name world /// @param seed Seed world @@ -122,41 +100,6 @@ static int l_delete_world(lua::State* L) { return 0; } -/// @brief Reconfigure packs -/// @param addPacks An array of packs to add -/// @param remPacks An array of packs to remove -static int l_reconfig_packs(lua::State* L) { - if (!lua::istable(L, 1)) { - throw std::runtime_error("strings array expected as the first argument"); - } - if (!lua::istable(L, 2)) { - throw std::runtime_error("strings array expected as the second argument"); - } - std::vector addPacks; - int addLen = lua::objlen(L, 1); - for (int i = 0; i < addLen; i++) { - lua::rawgeti(L, i + 1, 1); - addPacks.emplace_back(lua::require_lstring(L, -1)); - lua::pop(L); - } - std::vector remPacks; - int remLen = lua::objlen(L, 2); - for (int i = 0; i < remLen; i++) { - lua::rawgeti(L, i + 1, 2); - remPacks.emplace_back(lua::require_lstring(L, -1)); - lua::pop(L); - } - auto engineController = engine->getController(); - try { - engineController->reconfigPacks(controller, addPacks, remPacks); - } catch (const contentpack_error& err) { - throw std::runtime_error( - std::string(err.what()) + " [" + err.getPackId() + " ]" - ); - } - return 0; -} - static int l_blank(lua::State*) { return 0; } @@ -190,15 +133,12 @@ static int l_capture_output(lua::State* L) { const luaL_Reg corelib[] = { {"blank", lua::wrap}, - {"load_content", lua::wrap}, - {"reset_content", lua::wrap}, {"new_world", lua::wrap}, {"open_world", lua::wrap}, {"reopen_world", lua::wrap}, {"save_world", lua::wrap}, {"close_world", lua::wrap}, {"delete_world", lua::wrap}, - {"reconfig_packs", lua::wrap}, {"capture_output", lua::wrap}, {nullptr, nullptr} };