From a48b2d9a6680c38935f933254dd4760ae1314ae8 Mon Sep 17 00:00:00 2001 From: geneotech Date: Wed, 19 Jun 2024 22:00:28 +0200 Subject: [PATCH] Completely remove Lua --- CMakeLists.txt | 62 +- src/application/intercosm_io.hpp | 1 - .../setups/debugger/debugger_autosave.cpp | 2 +- .../setups/debugger/debugger_folder.cpp | 2 +- .../setups/debugger/debugger_recent_paths.cpp | 2 +- .../setups/debugger/debugger_setup.cpp | 2 +- src/augs/misc/lua/lua_utils.cpp | 54 -- src/augs/readwrite/lua_file.h | 124 ---- src/augs/readwrite/lua_readwrite.h | 529 ------------------ .../readwrite/lua_readwrite_declaration.h | 22 - src/augs/readwrite/lua_readwrite_errors.h | 8 - .../readwrite/lua_readwrite_overload_traits.h | 52 -- src/augs/readwrite/lua_traits.h | 51 -- src/game/cosmos/state_tests.cpp | 1 - src/test_scenes/test_scene_images.cpp | 1 - src/work.cpp | 1 - 16 files changed, 5 insertions(+), 909 deletions(-) delete mode 100644 src/augs/misc/lua/lua_utils.cpp delete mode 100644 src/augs/readwrite/lua_file.h delete mode 100644 src/augs/readwrite/lua_readwrite.h delete mode 100644 src/augs/readwrite/lua_readwrite_declaration.h delete mode 100644 src/augs/readwrite/lua_readwrite_errors.h delete mode 100644 src/augs/readwrite/lua_readwrite_overload_traits.h delete mode 100644 src/augs/readwrite/lua_traits.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d11c1f064..76f25eeefe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,8 +297,6 @@ set(STATICALLY_ALLOCATE_ENTITY_FLAVOURS OFF CACHE STRING "Statically allocate en ## Internal build flags for programmers' use. ## Don't set them manually without a good reason. -set (BUILD_LUA_AS_CPP OFF) - if (UNIX) set(OpenGL_GL_PREFERENCE "LEGACY") endif() @@ -332,44 +330,6 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") ##################################################### ### SPECIFICATION OF ALL SOURCE FILES BEGINS HERE ### -# We will be building Lua manually as there is no up-to-date CMakeLists for Lua. - -set(LUA_CPPS - "src/3rdparty/lua/lapi.c" - "src/3rdparty/lua/lauxlib.c" - "src/3rdparty/lua/lbaselib.c" - "src/3rdparty/lua/lbitlib.c" - "src/3rdparty/lua/lcode.c" - "src/3rdparty/lua/lcorolib.c" - "src/3rdparty/lua/lctype.c" - "src/3rdparty/lua/ldblib.c" - "src/3rdparty/lua/ldebug.c" - "src/3rdparty/lua/ldo.c" - "src/3rdparty/lua/ldump.c" - "src/3rdparty/lua/lfunc.c" - "src/3rdparty/lua/lgc.c" - "src/3rdparty/lua/linit.c" - "src/3rdparty/lua/liolib.c" - "src/3rdparty/lua/llex.c" - "src/3rdparty/lua/lmathlib.c" - "src/3rdparty/lua/lmem.c" - "src/3rdparty/lua/loadlib.c" - "src/3rdparty/lua/lobject.c" - "src/3rdparty/lua/lopcodes.c" - "src/3rdparty/lua/loslib.c" - "src/3rdparty/lua/lparser.c" - "src/3rdparty/lua/lstate.c" - "src/3rdparty/lua/lstring.c" - "src/3rdparty/lua/lstrlib.c" - "src/3rdparty/lua/ltable.c" - "src/3rdparty/lua/ltablib.c" - "src/3rdparty/lua/ltm.c" - "src/3rdparty/lua/lundump.c" - "src/3rdparty/lua/lutf8lib.c" - "src/3rdparty/lua/lvm.c" - "src/3rdparty/lua/lzio.c" -) - # We will be building Box2D manually, as it is hacked to the utmost. set(HYPERSOMNIA_BOX2D_CPPS @@ -816,7 +776,6 @@ set(HYPERSOMNIA_CODEBASE_CPPS "src/game/detail/spells/ultimate_wrath_of_the_aeons.cpp" "src/game/detail/spells/exaltation.cpp" "src/game/detail/spells/echoes_of_the_higher_realms.cpp" - "src/augs/misc/lua/lua_utils.cpp" "src/test_scenes/test_scenes_content.cpp" "src/game/assets/recoil_player.cpp" "src/augs/unit_tests.cpp" @@ -1021,10 +980,6 @@ endif() ### SPECIFICATION OF ALL SOURCE FILES END HERE ### ################################################## -if(BUILD_LUA_AS_CPP) - set_source_files_properties(${LUA_CPPS} PROPERTIES LANGUAGE CXX) -endif() - # We arrange the directories for the generated sources paths. set(GENERATORS_OUTPUT_PATH "${PROJECT_BINARY_DIR}/generators_output") @@ -1157,8 +1112,6 @@ set(HYPERSOMNIA_HEADERS set(HYPERSOMNIA_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_SOURCE_DIR}/src/3rdparty" - "${PROJECT_SOURCE_DIR}/src/3rdparty/lua" - "${PROJECT_SOURCE_DIR}/src/3rdparty/sol2/include" "${PROJECT_SOURCE_DIR}/src/3rdparty/imgui" "${PROJECT_SOURCE_DIR}/src/3rdparty/yojimbo/reliable" "${PROJECT_SOURCE_DIR}/src/3rdparty/yojimbo/netcode" @@ -1480,15 +1433,6 @@ add_definitions(-DLIBM_COMPILING_FLT32) add_definitions(-DIMGUI_USER_CONFIG="3rdparty/imconfig.h") add_definitions(-D_SILENCE_CXX20_U8PATH_DEPRECATION_WARNING) -if(UNIX) - add_definitions(-DLUA_USE_LINUX) -endif() - -if(BUILD_LUA_AS_CPP) - # Lua is configured to compile as C++, of which sol2 library must necessarily know. - add_definitions(-DSOL_USING_CXX_LUA) -endif() - # We must wait till SOL will fixes these warnings. add_definitions(-D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) @@ -1598,10 +1542,6 @@ endif() include(configure_runtime_library) configure_msvc_runtime() -# We build Lua manually as there is no up-to-date CMakeLists for Lua. - -add_library(lua ${LUA_CPPS}) - # As some libraries do not use the preferred target_include_directories, # we must manually acquire the directories that they add via include_directories. @@ -1872,7 +1812,7 @@ endif() # We define libraries upon which Hypersomnia depends. -set(HYPERSOMNIA_LIBS lua streflop blake3) +set(HYPERSOMNIA_LIBS streflop blake3) include_directories(${PROJECT_SOURCE_DIR}/cmake/steam_integration) diff --git a/src/application/intercosm_io.hpp b/src/application/intercosm_io.hpp index 40e280db8a..e0928aa97c 100644 --- a/src/application/intercosm_io.hpp +++ b/src/application/intercosm_io.hpp @@ -1,5 +1,4 @@ #pragma once -#include #include "augs/misc/pool/pool_io.hpp" #include "game/cosmos/per_entity_type.h" #include "augs/templates/for_each_type.h" diff --git a/src/application/setups/debugger/debugger_autosave.cpp b/src/application/setups/debugger/debugger_autosave.cpp index b0d41feb6d..55a13e8019 100644 --- a/src/application/setups/debugger/debugger_autosave.cpp +++ b/src/application/setups/debugger/debugger_autosave.cpp @@ -7,7 +7,7 @@ #include "application/setups/debugger/debugger_paths.h" #include "application/setups/debugger/debugger_significant.h" -#include "augs/readwrite/lua_file.h" +#include "augs/readwrite/json_readwrite.h" static void save_last_folders( sol::state& lua, diff --git a/src/application/setups/debugger/debugger_folder.cpp b/src/application/setups/debugger/debugger_folder.cpp index 74cefb38aa..5b82e186b0 100644 --- a/src/application/setups/debugger/debugger_folder.cpp +++ b/src/application/setups/debugger/debugger_folder.cpp @@ -8,7 +8,7 @@ #include "augs/misc/maybe_official_path.h" #include "augs/readwrite/byte_file.h" -#include "augs/readwrite/lua_file.h" +#include "augs/readwrite/json_readwrite.h" #include "game/cosmos/entity_handle.h" #include "hypersomnia_version.h" diff --git a/src/application/setups/debugger/debugger_recent_paths.cpp b/src/application/setups/debugger/debugger_recent_paths.cpp index f628654d38..05ca0e8d8f 100644 --- a/src/application/setups/debugger/debugger_recent_paths.cpp +++ b/src/application/setups/debugger/debugger_recent_paths.cpp @@ -1,7 +1,7 @@ #include "augs/templates/container_templates.h" #include "application/setups/debugger/debugger_recent_paths.h" #include "application/setups/debugger/debugger_paths.h" -#include "augs/readwrite/lua_file.h" +#include "augs/readwrite/json_readwrite.h" debugger_recent_paths::debugger_recent_paths(sol::state& lua) { try { diff --git a/src/application/setups/debugger/debugger_setup.cpp b/src/application/setups/debugger/debugger_setup.cpp index 3b81b4945d..84631c93af 100644 --- a/src/application/setups/debugger/debugger_setup.cpp +++ b/src/application/setups/debugger/debugger_setup.cpp @@ -32,7 +32,7 @@ #include "game/detail/calc_render_layer.h" #include "augs/readwrite/byte_file.h" -#include "augs/readwrite/lua_file.h" +#include "augs/readwrite/json_readwrite.h" #include "augs/filesystem/find_path.h" std::optional debugger_setup::find_screen_space_rect_selection( diff --git a/src/augs/misc/lua/lua_utils.cpp b/src/augs/misc/lua/lua_utils.cpp deleted file mode 100644 index c7949f01ae..0000000000 --- a/src/augs/misc/lua/lua_utils.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include - -#include "augs/log.h" -#include "augs/ensure.h" - -#include "augs/misc/lua/lua_utils.h" -#include "all_paths.h" - -namespace augs { - sol::state create_lua_state() { - sol::state lua; - - lua.open_libraries( - sol::lib::base, - sol::lib::package, - sol::lib::string, - sol::lib::os, - sol::lib::math, - sol::lib::table, - sol::lib::debug, - sol::lib::bit32, - sol::lib::io, - sol::lib::utf8 - ); - - lua["LOG"] = [](const std::string content) { - LOG(content); - }; - - lua["ensure"] = []( - const bool condition, - const std::string message - ) { - if (!condition) { - LOG(message); - ensure(false); - } - }; - - const auto utils_path = DETAIL_DIR / "utils.lua"; - LOG("Calling %x", utils_path); - const auto pfr = lua.do_file(utils_path.string()); - - if (!pfr.valid()) { - throw lua_state_creation_error( - "Failed to build %x:\n%x", utils_path, pfr.operator std::string() - ); - } - - LOG("Lua state created successfully."); - - return lua; - } -} \ No newline at end of file diff --git a/src/augs/readwrite/lua_file.h b/src/augs/readwrite/lua_file.h deleted file mode 100644 index 12eec2d153..0000000000 --- a/src/augs/readwrite/lua_file.h +++ /dev/null @@ -1,124 +0,0 @@ -#pragma once -#include "augs/filesystem/file.h" -#include "augs/readwrite/lua_readwrite.h" - -namespace augs { - template - auto to_lua_string( - sol::state& lua, - T&& object, - SaverArgs&&... args - ) { - auto output_table = lua.create_named_table("my_table"); - write_lua(output_table, std::forward(object)); - - const std::string serialized_table = lua["table_to_string"]( - output_table, - std::forward(args)... - ); - - return std::string("return ") + serialized_table; - } - - template - void save_as_lua_table( - sol::state& lua, - T&& object, - const path_type& target_path, - SaverArgs&&... args - ) { - save_as_text( - target_path, - to_lua_string(lua, object, std::forward(args)...) - ); - } - - template - void save_as_lua_patch( - sol::state& lua, - T&& source, - T&& target, - const path_type& target_path, - SaverArgs&&... args - ) { - auto source_table = lua.create_named_table("source_table"); - write_lua(source_table, std::forward(source)); - - auto target_table = lua.create_named_table("target_table"); - write_lua(target_table, std::forward(target)); - - const std::string serialized_table = lua["table_diff_to_string"]( - source_table, - target_table, - std::forward(args)... - ); - - const auto table_file_contents = std::string("return ") + serialized_table; - - save_as_text( - target_path, - table_file_contents - ); - } - - template - void load_from_lua_patch( - sol::state& lua, - T& object, - const path_type& patch_path - ) { - auto source_table = lua.create_named_table("source_table"); - write_lua(source_table, std::forward(object)); - - auto pfr = lua.do_string( - file_to_string(patch_path) - ); - - if (!pfr.valid()) { - throw lua_deserialization_error( - "Failed to obtain patch table from %x:\n%x", - patch_path, - pfr.operator std::string() - ); - } - - sol::table patch_table = pfr; - - auto patched_table = lua["patch_table"]( - source_table, - patch_table - ); - - read_lua(patched_table, object); - } - - template - void load_from_lua_table( - sol::state& lua, - T& object, - const path_type& source_path - ) { - auto pfr = lua.do_string( - file_to_string(source_path) - ); - - if (!pfr.valid()) { - throw lua_deserialization_error( - "Failed to obtain table from %x:\n%x", - source_path, - pfr.operator std::string() - ); - } - - sol::table input_table = pfr; - read_lua(input_table, object); - } - - template - T load_from_lua_table(sol::state& lua, const path_type& source_path) { - T object{}; - load_from_lua_table(lua, object, source_path); - return object; - } -} - diff --git a/src/augs/readwrite/lua_readwrite.h b/src/augs/readwrite/lua_readwrite.h deleted file mode 100644 index ea4b456555..0000000000 --- a/src/augs/readwrite/lua_readwrite.h +++ /dev/null @@ -1,529 +0,0 @@ -#pragma once -#include - -#include "augs/ensure.h" -#include "augs/log.h" -#include "augs/pad_bytes.h" - -#include "augs/string/get_type_name.h" -#include "augs/templates/traits/is_variant.h" -#include "augs/templates/traits/is_monostate.h" -#include "augs/templates/traits/is_optional.h" -#include "augs/templates/traits/is_maybe.h" -#include "augs/templates/traits/is_pair.h" -#include "augs/misc/is_constant_size_string.h" -#include "augs/readwrite/lua_readwrite_errors.h" -#include "augs/templates/container_templates.h" -#include "augs/templates/introspect.h" -#include "augs/templates/for_each_type.h" -#include "augs/templates/identity_templates.h" - -#include "augs/string/string_to_enum.h" - -#include "augs/readwrite/custom_lua_representations.h" -#include "augs/misc/lua/lua_utils.h" - -#include "augs/readwrite/lua_readwrite_declaration.h" -#include "augs/readwrite/lua_readwrite_overload_traits.h" -#include "augs/readwrite/lua_traits.h" -#include "augs/misc/enum/enum_boolset.h" -#include "augs/misc/enum/is_enum_boolset.h" - -namespace augs { - template - inline const char* get_variant_type_label(T&&...) { - return "kind"; - } - - template - inline const char* get_variant_content_label(T&&...) { - return "content"; - } - - template - void general_from_lua_value(const sol::object& object, T& into) { - if constexpr(std::is_pointer_v) { - into = nullptr; - } - else if constexpr(has_custom_to_lua_value_v) { - from_lua_value(object, into); - } - else if constexpr(is_constant_size_string_v) { - if (object.is()) { - into = object.as(); - } - } - else if constexpr(std::is_same_v || std::is_arithmetic_v) { - if (object.is()) { - into = object.as(); - } - } - else if constexpr(std::is_enum_v) { - if (object.is()) { - const auto stringized_enum = object.as(); - - if ( - const auto* enumized = mapped_or_nullptr( - get_string_to_enum_map(), - stringized_enum - ) - ) { - into = *enumized; - } - else { - LOG( - "Failed to read \"%x\" into %x enum. Check if such option exists, or if spelling is correct.", - stringized_enum, - get_type_name() - ); - } - } - } - else { - static_assert(always_false_v, "Non-exhaustive general_from_lua_value"); - } - } - - template - void verify_read_lua() { - static_assert( - !is_optional_v && !is_maybe_v, - "std::optional and maybe can only be serialized as a member object." - ); - - static_assert(!std::is_const_v, "Trying to read into a const object."); - } - - template - void read_lua(const Archive& input_object, Serialized& into) { - verify_read_lua(); - - if constexpr(has_lua_read_overload_v) { - static_assert(has_lua_write_overload_v, "Has read_object_lua overload, but no write_object_lua overload."); - - sol::table input_table = input_object; - read_object_lua(input_table, into); - } - else { - read_lua_no_overload(input_object, into); - } - } - - template - void read_lua_no_overload(const Archive& input_object, Serialized& into) { - verify_read_lua(); - - if constexpr(is_variant_v) { - sol::table input_table = input_object; - ensure(input_table.is()); - - const auto variant_type_label = get_variant_type_label(into); - std::string variant_type = input_table[variant_type_label]; - - if (variant_type == "std_monostate") { - return; - } - - const auto variant_content_label = get_variant_content_label(into); - sol::object variant_content = input_table[variant_content_label]; - - for_each_type_in_list( - [variant_content, variant_type, &into](const auto& resolved){ - if constexpr(!is_monostate_v) { - const auto this_type_name = get_type_name_strip_namespace(resolved); - - if (this_type_name == variant_type) { - using T = remove_cref; - T object{}; - read_lua(variant_content, object); - into.template emplace(std::move(object)); - } - } - } - ); - } - else if constexpr(representable_as_lua_value_v) { - general_from_lua_value(input_object, into); - } - else { - sol::table input_table = input_object; - ensure(input_table.is() && "This must be read from a table, not a value."); - - if constexpr(is_container_v) { - using Container = Serialized; - - if constexpr(can_clear_v) { - into.clear(); - } - else { - into = {}; - } - - /* - If container is associative and the keys are representable as lua values, - read container table as: - - { - ab = "abc", - cd = "cde" - } - - otherwise, read container table as a sequence of key-value pairs (like vector): - - { - { "ab", "abc" }, - { "cd", "cde" } - } - */ - - if constexpr(is_associative_v && key_representable_as_lua_value_v) { - for (auto key_value_pair : input_table) { - typename Container::key_type key{}; - typename Container::mapped_type mapped{}; - - general_from_lua_value(key_value_pair.first, key); - read_lua(key_value_pair.second, mapped); - - into.emplace(std::move(key), std::move(mapped)); - } - } - else if constexpr(is_enum_array_v) { - augs::for_each_enum_except_bounds([&](typename Container::enum_type e) { - auto maybe_entry = input_table[augs::enum_to_string(e)]; - - if (maybe_entry.valid()) { - read_lua(maybe_entry, into[e]); - } - }); - } - else if constexpr(is_enum_boolset_v) { - using E = typename Container::enum_type; - - into.reset(); - - int counter = 1; - - while (true) { - sol::object maybe_element = input_table[counter]; - - if (maybe_element.valid()) { - E e; - general_from_lua_value(maybe_element, e); - into[e] = true; - } - else { - break; - } - - ++counter; - } - } - else if constexpr(is_std_array_v) { - for (std::size_t i = 0; i < into.size(); ++i) { - read_lua(input_table[static_cast(i + 1)], into[i]); - } - } - else { - int counter = 1; - - const auto max_size = into.max_size(); - - while (true) { - if (into.size() >= max_size) { - break; - } - - sol::object maybe_element = input_table[counter]; - - if (maybe_element.valid()) { - if constexpr(is_associative_v) { - typename Container::key_type key{}; - typename Container::mapped_type mapped{}; - - ensure(maybe_element.is()); - - sol::table key_value_table = maybe_element; - - ensure(key_value_table[1].valid()); - ensure(key_value_table[2].valid()); - - read_lua(key_value_table[1], key); - read_lua(key_value_table[2], mapped); - - into.emplace(std::move(key), std::move(mapped)); - } - else { - typename Container::value_type val; - - read_lua(input_table[counter], val); - - if constexpr(can_emplace_back_v) { - into.emplace_back(std::move(val)); - } - else { - into.emplace(std::move(val)); - } - } - } - else { - break; - } - - ++counter; - } - } - } - else if constexpr(is_pair_v) { - sol::object maybe_first = input_table[1]; - sol::object maybe_second = input_table[2]; - - if (maybe_first.valid() && maybe_second.valid()) { - read_lua(maybe_first, into.first); - read_lua(maybe_second, into.second); - } - } - else { - introspect( - [&input_table](const auto& label, auto& field) { - using T = remove_cref; - - if constexpr(is_optional_v) { - sol::object maybe_field = input_table[label]; - - if (maybe_field.valid()) { - if (field == std::nullopt) { - field.emplace(); - } - - read_lua(maybe_field, *field); - } - } - else if constexpr(is_maybe_v) { - if constexpr(T::serialize_disabled) { - if (sol::object enabled_field = input_table[std::string("enabled_") + label]; - enabled_field.valid() - ) { - read_lua(enabled_field, field.value); - field.is_enabled = true; - } - - if (sol::object disabled_field = input_table[std::string("disabled_") + label]; - disabled_field.valid() - ) { - read_lua(disabled_field, field.value); - field.is_enabled = false; - } - } - else { - if (sol::object disabled_field = input_table[label]; - disabled_field.valid() - ) { - read_lua(disabled_field, field.value); - field.is_enabled = false; - } - } - } - else if constexpr(!is_padding_field_v) { - sol::object maybe_field = input_table[label]; - - const bool field_specified = maybe_field.valid(); - - if (field_specified) { - read_lua(maybe_field, field); - } - } - }, - into - ); - } - } - } - - template - decltype(auto) general_to_lua_value(const T& field) { - if constexpr(std::is_pointer_v) { - return general_to_lua_value(*field); - } - else if constexpr(has_custom_to_lua_value_v) { - return to_lua_value(field); - } - else if constexpr(is_constant_size_string_v) { - return field.operator std::string(); - } - else if constexpr(std::is_same_v || std::is_arithmetic_v) { - return field; - } - else if constexpr(std::is_enum_v) { - return enum_to_string(field); - } - else { - static_assert(always_false_v, "Non-exhaustive to_lua_representation"); - } - } - - template - void write_table_or_field(sol::table& output_table, const T& from, K&& key) { - if constexpr(representable_as_lua_value_v) { - output_table[std::forward(key)] = general_to_lua_value(from); - } - else { - auto new_table = output_table.create(); - write_lua(new_table, from); - output_table[std::forward(key)] = new_table; - } - } - - template - void verify_write_lua() { - static_assert( - !representable_as_lua_value_v, - "Directly representable, but no key (label) provided! Use write_representable_field to directly serialize this object." - ); - - static_assert( - !is_optional_v && !is_maybe_v, - "std::optional can only be serialized as a member object." - ); - } - - template - void write_lua(Archive& output_table, const Serialized& from) { - verify_write_lua(); - - if constexpr(has_lua_write_overload_v) { - static_assert(has_lua_read_overload_v, "Has write_object_lua overload, but no read_object_lua overload."); - - write_object_lua(output_table, from); - } - else { - write_lua_no_overload(output_table, from); - } - } - template - void write_lua_no_overload(Archive& output_table, const Serialized& from) { - verify_write_lua(); - - if constexpr(is_variant_v) { - const auto variant_type_label = get_variant_type_label(from); - const auto variant_content_label = get_variant_content_label(from); - - std::visit( - [&](const auto& resolved) mutable { - if constexpr(is_monostate_v) { - output_table[variant_type_label] = "std_monostate"; - } - else { - const auto this_type_name = get_type_name_strip_namespace(resolved); - output_table[variant_type_label] = this_type_name; - write_table_or_field(output_table, resolved, variant_content_label); - } - }, - from - ); - } - else if constexpr(is_container_v) { - using Container = Serialized; - - /* - If container is associative and the keys are representable as lua values, - write container table as: - - { - ab = "abc", - cd = "cde" - } - - otherwise, write container table as a sequence of key-value pairs (like vector): - - { - { "ab", "abc" }, - { "cd", "cde" } - } - */ - - if constexpr(is_associative_v && key_representable_as_lua_value_v) { - for (auto&& element : from) { - write_table_or_field(output_table, element.second, general_to_lua_value(element.first)); - } - } - else if constexpr(is_enum_array_v) { - augs::for_each_enum_except_bounds([&](typename Container::enum_type e) { - write_table_or_field(output_table, from[e], general_to_lua_value(e)); - }); - } - else if constexpr(is_enum_boolset_v) { - using E = typename Container::enum_type; - - int counter = 1; - - augs::for_each_enum_except_bounds([&](const E e) { - if (from[e]) { - const auto entry_name = augs::enum_to_string(e); - output_table[counter] = entry_name; - ++counter; - } - }); - } - else if constexpr(is_std_array_v) { - for (std::size_t i = 0; i < from.size(); ++i) { - write_table_or_field(output_table, from[i], static_cast(i + 1)); - } - } - else { - int counter = 1; - - for (auto&& element : from) { - if constexpr(is_associative_v) { - auto key_value_pair_table = output_table.create(); - - write_table_or_field(key_value_pair_table, element.first, 1); - write_table_or_field(key_value_pair_table, element.second, 2); - - output_table[counter] = key_value_pair_table; - } - else { - write_table_or_field(output_table, element, counter); - } - - ++counter; - } - } - } - else if constexpr(is_pair_v) { - write_table_or_field(output_table, from.first, 1); - write_table_or_field(output_table, from.second, 2); - } - else { - introspect( - [&output_table](const auto& label, const auto& field) { - using T = remove_cref; - - if constexpr(is_optional_v) { - if (field) { - write_table_or_field(output_table, field.value(), label); - } - } - else if constexpr(is_maybe_v) { - if constexpr(T::serialize_disabled) { - if (field) { - write_table_or_field(output_table, field.value, std::string("enabled_") + label); - } - else { - write_table_or_field(output_table, field.value, std::string("disabled_") + label); - } - } - else { - if (field) { - write_table_or_field(output_table, field.value, label); - } - } - } - else if constexpr(!is_padding_field_v) { - write_table_or_field(output_table, field, label); - } - }, - from - ); - } - } -} \ No newline at end of file diff --git a/src/augs/readwrite/lua_readwrite_declaration.h b/src/augs/readwrite/lua_readwrite_declaration.h deleted file mode 100644 index 3ba54f3560..0000000000 --- a/src/augs/readwrite/lua_readwrite_declaration.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include - -namespace augs { - template - void write_lua(Archive&, const Serialized& from); - - template - void read_lua(const Archive&, Serialized& into); - - template - void write_lua_no_overload(Archive&, const Serialized& from); - - template - void read_lua_no_overload(const Archive&, Serialized& into); - - template - void write_table_or_field(sol::table& output_table, const T& from, K&& key); - - template - void general_from_lua_value(const sol::object& object, T& into); -} diff --git a/src/augs/readwrite/lua_readwrite_errors.h b/src/augs/readwrite/lua_readwrite_errors.h deleted file mode 100644 index b6ef81c443..0000000000 --- a/src/augs/readwrite/lua_readwrite_errors.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "augs/templates/exception_templates.h" - -namespace augs { - struct lua_deserialization_error : error_with_typesafe_sprintf { - using error_with_typesafe_sprintf::error_with_typesafe_sprintf; - }; -} diff --git a/src/augs/readwrite/lua_readwrite_overload_traits.h b/src/augs/readwrite/lua_readwrite_overload_traits.h deleted file mode 100644 index b28aed64fc..0000000000 --- a/src/augs/readwrite/lua_readwrite_overload_traits.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once -#include -#include - -#define LUA_READWRITE_OVERLOAD_TRAITS_INCLUDED 1 - -namespace augs { - template - struct has_lua_read_overload : std::false_type - {}; - - template - struct has_lua_read_overload < - type_list, - decltype( - read_object_lua( - std::declval(), - std::declval()... - ), - void() - ) - > : std::true_type - {}; - - template - struct has_lua_write_overload : std::false_type - {}; - - template - struct has_lua_write_overload < - type_list, - decltype( - write_object_lua( - std::declval(), - std::declval()... - ), - void() - ) - > : std::true_type - {}; - - template - constexpr bool has_lua_read_overload_v = has_lua_read_overload>::value; - - template - constexpr bool has_lua_write_overload_v = has_lua_write_overload>::value; - - template - constexpr bool has_lua_readwrite_overloads_v = - has_lua_read_overload_v && has_lua_write_overload_v - ; -} diff --git a/src/augs/readwrite/lua_traits.h b/src/augs/readwrite/lua_traits.h deleted file mode 100644 index 8f04d01e11..0000000000 --- a/src/augs/readwrite/lua_traits.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once -#include -#include "augs/misc/is_constant_size_string.h" - -#define LUA_TRAITS_INCLUDED 1 - -namespace augs { - template - struct has_custom_to_lua_value : std::false_type {}; - - template - struct has_custom_to_lua_value< - T, - decltype( - to_lua_value( - std::declval() - ), - from_lua_value( - std::declval(), - std::declval() - ), - void() - ) - > : std::true_type {}; - - template - constexpr bool has_custom_to_lua_value_v = has_custom_to_lua_value::value; - - template - constexpr bool representable_as_lua_value_v = - std::is_same_v - || is_constant_size_string_v - || std::is_arithmetic_v - || std::is_enum_v - || has_custom_to_lua_value_v - ; - - template - constexpr bool representable_as_lua_value_v = representable_as_lua_value_v>; - - template - struct key_representable_as_lua_value : std::false_type {}; - - template - struct key_representable_as_lua_value - : std::bool_constant> { - }; - - template - static constexpr bool key_representable_as_lua_value_v = key_representable_as_lua_value::value; -} \ No newline at end of file diff --git a/src/game/cosmos/state_tests.cpp b/src/game/cosmos/state_tests.cpp index c307d138c4..6553868107 100644 --- a/src/game/cosmos/state_tests.cpp +++ b/src/game/cosmos/state_tests.cpp @@ -16,7 +16,6 @@ #include "game/organization/for_each_component_type.h" #include "augs/readwrite/byte_readwrite.h" -#include "augs/readwrite/lua_readwrite.h" #include "augs/log_path_getters.h" TEST_CASE("StateTest0 PaddingSanityCheck1") { diff --git a/src/test_scenes/test_scene_images.cpp b/src/test_scenes/test_scene_images.cpp index 96e4a67cff..a95ac7ac2e 100644 --- a/src/test_scenes/test_scene_images.cpp +++ b/src/test_scenes/test_scene_images.cpp @@ -11,7 +11,6 @@ #include "test_scenes/test_scene_images.h" #include "test_scenes/test_enum_to_path.h" -#include "augs/readwrite/lua_readwrite_errors.h" #include "view/load_meta_json.h" #include "augs/log_direct.h" diff --git a/src/work.cpp b/src/work.cpp index fd767ceae7..8854de996e 100644 --- a/src/work.cpp +++ b/src/work.cpp @@ -27,7 +27,6 @@ #include #endif -#include #include #include "augs/templates/enum_introspect.h"