diff --git a/.cmake-format.json b/.cmake-format.json new file mode 100644 index 00000000..f0c505c3 --- /dev/null +++ b/.cmake-format.json @@ -0,0 +1,6 @@ +{ + "format": { + "line_width": 100, + "use_tabchars": true + } +} diff --git a/.editorconfig b/.editorconfig index bc97b69a..218304f5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,10 @@ root = true [*] guidelines = 100 indent_style = tab -indent_size = 4 +indent_size = 2 # Unix-style newlines end_of_line = lf insert_final_newline = true + +[CMakeLists.txt] +max_line_length = 100 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c7b7cae..a6b6b6f3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,7 @@ on: branches: - master pull_request: + workflow_dispatch: env: BUILD_TYPE: release diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 38ab6a8d..55f7478b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: hooks: - id: text-unicode-replacement-char - repo: https://github.com/cheshirekow/cmake-format-precommit - rev: v0.6.10 + rev: v0.6.13 hooks: - id: cmake-format - id: cmake-lint diff --git a/CMakeLists.txt b/CMakeLists.txt index 490af3e7..cebfd9f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,21 +4,21 @@ if(${CMAKE_VERSION} VERSION_GREATER "3.24.0") cmake_policy(SET CMP0135 NEW) endif() include(FetchContent) -FetchContent_Declare(inklecate_mac -URL https://github.com/inkle/ink/releases/download/v1.1.1/inklecate_mac.zip -URL_HASH SHA256=c516402bca5fa249a7712e62591b048b137eba3098c53f9fb85a4253f9b9e2c0 -SOURCE_DIR "${CMAKE_BINARY_DIR}/inklecate/mac" -) -FetchContent_Declare(inklecate_windows -URL https://github.com/inkle/ink/releases/download/v1.1.1/inklecate_windows.zip -URL_HASH SHA256=6f317cb4c59bf1b31c6dd61e80c6a2287a1d8c241a703f0586f736ae00871aab -SOURCE_DIR "${CMAKE_BINARY_DIR}/inklecate/windows" -) -FetchContent_Declare(inklecate_linux -URL https://github.com/inkle/ink/releases/download/v1.1.1/inklecate_linux.zip -URL_HASH SHA256=26f4e188e02536d6e99e73e71d9b13e2c2144187f1368a87e82fd5066176cff8 -SOURCE_DIR "${CMAKE_BINARY_DIR}/inklecate/linux" -) +FetchContent_Declare( + inklecate_mac + URL https://github.com/inkle/ink/releases/download/v1.1.1/inklecate_mac.zip + URL_HASH SHA256=c516402bca5fa249a7712e62591b048b137eba3098c53f9fb85a4253f9b9e2c0 + SOURCE_DIR "${CMAKE_BINARY_DIR}/inklecate/mac") +FetchContent_Declare( + inklecate_windows + URL https://github.com/inkle/ink/releases/download/v1.1.1/inklecate_windows.zip + URL_HASH SHA256=6f317cb4c59bf1b31c6dd61e80c6a2287a1d8c241a703f0586f736ae00871aab + SOURCE_DIR "${CMAKE_BINARY_DIR}/inklecate/windows") +FetchContent_Declare( + inklecate_linux + URL https://github.com/inkle/ink/releases/download/v1.1.1/inklecate_linux.zip + URL_HASH SHA256=26f4e188e02536d6e99e73e71d9b13e2c2144187f1368a87e82fd5066176cff8 + SOURCE_DIR "${CMAKE_BINARY_DIR}/inklecate/linux") set(FETCHCONTENT_QUIET OFF) mark_as_advanced(FETCHCONTENT_QUIET) set(CMAKE_TLS_VERIFY true) @@ -42,46 +42,67 @@ enable_testing() # Project setup project(inkcpp VERSION 0.1.9) -SET(CMAKE_CXX_STANDARD 17) -SET(CMAKE_CXX_STANDARD_REQUIRED ON) -SET(CMAKE_INSTALL_LIBRARY_DIR lib) -SET(CMAKE_INSTALL_INCLUDE_DIR include) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_INSTALL_LIBRARY_DIR lib) +set(CMAKE_INSTALL_INCLUDE_DIR include) # Add subdirectories include(CMakeDependentOption) option(INKCPP_PY "Build python bindings" OFF) -cmake_dependent_option(WHEEL_BUILD "Set for build wheel python lib. (see setup.py for ussage)" OFF "INKCPP_PY" OFF) +cmake_dependent_option(WHEEL_BUILD "Set for build wheel python lib. (see setup.py for ussage)" OFF + "INKCPP_PY" OFF) option(INKCPP_C "Build c library" OFF) -option(INKCPP_TEST "Build inkcpp tests (requires: inklecate in path / env: INKLECATE set / INKCPP_INKLECATE=OS or ALL)" OFF) -set(INKCPP_INKLECATE "NONE" CACHE STRING "If inklecate should be downloaded automatically from the official release page. NONE -> No, OS -> Yes, but only for the current OS, ALL -> Yes, for all availible OSs") +option(INKCPP_TEST "Build inkcpp tests (requires: inklecate in path / env: INKLECATE set \ + / INKCPP_INKLECATE=OS or ALL)" OFF) +set(INKCPP_INKLECATE + "NONE" + CACHE STRING "If inklecate should be downloaded automatically from the official release page. \ + NONE -> No, OS -> Yes, but only for the current OS, ALL -> Yes, for all availible OSs") set_property(CACHE INKCPP_INKLECATE PROPERTY STRINGS "NONE" "OS" "ALL") +option(INKCPP_NO_EH "Disable try/catch in runtime. Used to build without error handling." OFF) +option(INKCPP_NO_RTTI + "Disable real time type information depended code. Used to build without RTTI." OFF) + +if(INKCPP_NO_EH) + add_definitions(-DINKCPP_NO_EH) +endif() +if(INKCPP_NO_RTTI) + add_definitions(-DINKCPP_NO_RTTI) +endif() string(TOUPPER "${INKCPP_INKLECATE}" inkcpp_inklecate_upper) -if (inkcpp_inklecate_upper STREQUAL "ALL") +if(inkcpp_inklecate_upper STREQUAL "ALL") FetchContent_MakeAvailable(inklecate_windows inklecate_mac inklecate_linux) -elseif(inkcpp_inklecate_upper STREQUAL "OS") +elseif(inkcpp_inklecate_upper STREQUAL "OS") if(UNIX AND NOT APPLE) FetchContent_MakeAvailable(inklecate_linux) elseif(APPLE) FetchContent_MakeAvailable(inklecate_mac) - elseif(MSYS OR MINGW OR WIN32 OR CYGWIN) + elseif( + MSYS + OR MINGW + OR WIN32 + OR CYGWIN) FetchContent_MakeAvailable(inklecate_windows) else() - message(FATAL_ERROR "Unable to identify OS for option INKCPP_INKLECATE=OS, please consider using NONE or ALL.") + message( + FATAL_ERROR + "Unable to identify OS for option INKCPP_INKLECATE=OS, please consider using NONE or ALL.") endif() endif() -if (INKCPP_PY) +if(INKCPP_PY) add_compile_options(-fPIC) add_subdirectory(inkcpp_python) endif(INKCPP_PY) add_subdirectory(shared) add_subdirectory(inkcpp) add_subdirectory(inkcpp_compiler) -if (INKCPP_C) +if(INKCPP_C) add_subdirectory(inkcpp_c) endif(INKCPP_C) -if (NOT WHEEL_BUILD) +if(NOT WHEEL_BUILD) add_subdirectory(inkcpp_cl) if(INKCPP_TEST) add_subdirectory(inkcpp_test) @@ -89,35 +110,40 @@ if (NOT WHEEL_BUILD) add_subdirectory(unreal) endif(NOT WHEEL_BUILD) - -install(TARGETS inkcpp inkcpp_shared inkcpp_compiler +install( + TARGETS inkcpp inkcpp_shared inkcpp_compiler EXPORT inkcppTarget ARCHIVE DESTINATION "lib/ink" - COMPONENT lib EXCLUDE_FROM_ALL - PUBLIC_HEADER DESTINATION "include/ink" - COMPONENT lib EXCLUDE_FROM_ALL -) + COMPONENT lib + EXCLUDE_FROM_ALL + PUBLIC_HEADER + DESTINATION "include/ink" + COMPONENT lib + EXCLUDE_FROM_ALL) -install(EXPORT inkcppTarget - FILE inkcppTargets.cmake DESTINATION "lib/cmake/inkcpp" - COMPONENT lib EXCLUDE_FROM_ALL) +install( + EXPORT inkcppTarget + FILE inkcppTargets.cmake + DESTINATION "lib/cmake/inkcpp" + COMPONENT lib + EXCLUDE_FROM_ALL) include(CMakePackageConfigHelpers) -configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in - "${CMAKE_CURRENT_BINARY_DIR}/inkcppConfig.cmake" +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/inkcppConfig.cmake" INSTALL_DESTINATION "lib/cmake/inkcpp" - NO_SET_AND_CHECK_MACRO - NO_CHECK_REQUIRED_COMPONENTS_MACRO) + NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/inkcppConfigVersion.cmake" VERSION "${inkcpp_VERSION_MAJOR}.${inkcpp_VERSION_MINOR}" COMPATIBILITY AnyNewerVersion) -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/inkcppConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/inkcppConfigVersion.cmake - DESTINATION lib/cmake/inkcpp COMPONENT lib EXCLUDE_FROM_ALL) -export(EXPORT inkcppTarget - FILE "${CMAKE_CURRENT_BINARY_DIR}/inkcppTargets.cmake") +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/inkcppConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/inkcppConfigVersion.cmake + DESTINATION lib/cmake/inkcpp + COMPONENT lib + EXCLUDE_FROM_ALL) +export(EXPORT inkcppTarget FILE "${CMAKE_CURRENT_BINARY_DIR}/inkcppTargets.cmake") # include(InstallRequiredSystemLibraries) set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt") @@ -130,78 +156,103 @@ set(CPACK_COMPONENTS_GROUPING IGNORE) include(CPack) if(NOT WHEEL_BUILD) -find_package(Doxygen) -if (DOXYGEN_FOUND) - option(INKCPP_DOC_BlueprintUE "Building doxygen documentation with BlueprintUE visualisation for unreal blueprints. (Requires node js)" ON) - if (INKCPP_DOC_BlueprintUE) - set(NODEJS_HINT "None" CACHE PATH "Directory of NodeJS executable to use for generating BlueprintUE visualisation.") - if (IS_DIRECTORY "${NODEJS_HINT}") - find_program(NODEJS_PATH node HINTS ${NODEJS_HINT} DOC "NodeJS executable to build BlueprintUE visualisation in documentation.") - else() - find_program(NODEJS_PATH node DOC "NodeJS executable to build BlueprintUE visualisation in documentation.") - endif (IS_DIRECTORY "${NODEJS_HINT}") - if ("${NODEJS_PATH}" STREQUAL "NODEJS-NOTFOUND") - message(SEND_ERROR "NodeJS is required to build BlueprintUE visualisation. But it was not found. Install NodeJS set NODEJS_HINT to a directory containing the executable. Or disable building the visualisation with setting INKCPP_DOC_BlueprintUE=OFF") - endif("${NODEJS_PATH}" STREQUAL "NODEJS-NOTFOUND") - endif(INKCPP_DOC_BlueprintUE) + find_package(Doxygen) + if(DOXYGEN_FOUND) + option(INKCPP_DOC_BlueprintUE + "Building doxygen documentation with BlueprintUE visualisation for unreal blueprints. \ + (Requires node js)" ON) + if(INKCPP_DOC_BlueprintUE) + set(NODEJS_HINT + "None" + CACHE PATH + "Directory of NodeJS executable to use for generating BlueprintUE visualisation.") + if(IS_DIRECTORY "${NODEJS_HINT}") + find_program( + NODEJS_PATH node + HINTS ${NODEJS_HINT} + DOC "NodeJS executable to build BlueprintUE visualisation in documentation.") + else() + find_program(NODEJS_PATH node + DOC "NodeJS executable to build BlueprintUE visualisation in documentation.") + endif(IS_DIRECTORY "${NODEJS_HINT}") + if("${NODEJS_PATH}" STREQUAL "NODEJS-NOTFOUND") + message( + SEND_ERROR + "NodeJS is required to build BlueprintUE visualisation. \ + But it was not found. Install NodeJS set NODEJS_HINT \ + to a directory containing the executable. \ + Or disable building the visualisation with setting INKCPP_DOC_BlueprintUE=OFF") + endif("${NODEJS_PATH}" STREQUAL "NODEJS-NOTFOUND") + endif(INKCPP_DOC_BlueprintUE) - set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME}) - # enable if update to cmake version 3.28 - # doxygen_add_docs(doc WORKING_DIR ${PROJECT_SOURCE_DIR} CONFIG_FILE "${PROJECT_SOURCE_DIR}/Doxyfile" COMMENT "Generate docs") - set(INPUT_FILTER "") + set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME}) + # enable if update to cmake version 3.28 doxygen_add_docs(doc WORKING_DIR ${PROJECT_SOURCE_DIR} + # CONFIG_FILE "${PROJECT_SOURCE_DIR}/Doxyfile" COMMENT "Generate docs") + set(INPUT_FILTER "") - if (INKCPP_DOC_BlueprintUE AND NOT "${NODEJS_PATH}" STREQUAL "NODEJS-NOTFOUND") - # TODO: make as dependecy - file(COPY "${PROJECT_SOURCE_DIR}/unreal/blueprint_filter.js" DESTINATION ${PROJECT_BINARY_DIR}) - # file(DOWNLOAD - # "https://raw.githubusercontent.com/blueprintue/blueprintue-self-hosted-edition/main/www/bue-render/render.css" - # "${PROJECT_BINARY_DIR}/render.css" - # EXPECTED_HASH SHA256=875364e36f8aa5d6c1d41d58043f13b48a499b5c969e8daef35bd29bbf7c6e8d) - file(COPY "${PROJECT_SOURCE_DIR}/unreal/render.css" DESTINATION ${PROJECT_BINARY_DIR}) - file(APPEND "${PROJECT_BINARY_DIR}/render.css" ".bue-render .icon { background-color: unset; }") - file(READ "${PROJECT_SOURCE_DIR}/Doxyfile" DOXYFILE) - string(REPLACE "FILTER_PATTERNS =" "FILTER_PATTERNS = \"*/unreal/*=node ${PROJECT_BINARY_DIR}/blueprint_filter.js\"" DOXYFILE2 ${DOXYFILE}) - string(REPLACE "HTML_EXTRA_STYLESHEET =" "HTML_EXTRA_STYLESHEET = ${PROJECT_BINARY_DIR}/render.css " DOXYFILE ${DOXYFILE2}) - file(WRITE "${PROJECT_BINARY_DIR}/Doxyfile" ${DOXYFILE}) - else () - configure_file( - "${PROJECT_SOURCE_DIR}/Doxyfile" - "${PROJECT_BINARY_DIR}/Doxyfile" - COPYONLY) - endif() -# "Build Doxygen documentation in ${PROJECT_SOURCE_DIR}/Documentation." "To view them you can for example use" "'python -m http.server -d \"${PROJECT_SOURCE_DIR}/Documentation\" 8080'" "'explorer http://localhost:8080/html'" - add_custom_target(doc - ${DOXYGEN_EXECUTABLE} "${PROJECT_BINARY_DIR}/Doxyfile" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" - COMMAND ${CMAKE_COMMAND} -E echo - COMMENT "Generate DoxygenDocumentation") - add_custom_command(TARGET doc POST_BUILD - COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan - "Build Doxygen documentation in ${PROJECT_SOURCE_DIR}/Documentation." - "To view them you can for example use" - "\" python -m http.server -d \\\"${PROJECT_SOURCE_DIR}/Documentation\\\" 8080\"" - " explorer http://localhost:8080/html") + if(INKCPP_DOC_BlueprintUE AND NOT "${NODEJS_PATH}" STREQUAL "NODEJS-NOTFOUND") + # TODO: make as dependecy + file(COPY "${PROJECT_SOURCE_DIR}/unreal/blueprint_filter.js" + DESTINATION ${PROJECT_BINARY_DIR}) + # file(DOWNLOAD "https://raw.githubusercontent.com/blueprintue/ \ + # blueprintue-self-hosted-edition/main/www/bue-render/render.css" + # "${PROJECT_BINARY_DIR}/render.css" EXPECTED_HASH + # SHA256=875364e36f8aa5d6c1d41d58043f13b48a499b5c969e8daef35bd29bbf7c6e8d) + file(COPY "${PROJECT_SOURCE_DIR}/unreal/render.css" DESTINATION ${PROJECT_BINARY_DIR}) + file(APPEND "${PROJECT_BINARY_DIR}/render.css" + ".bue-render .icon { background-color: unset; }") + file(READ "${PROJECT_SOURCE_DIR}/Doxyfile" DOXYFILE) + string( + REPLACE + "FILTER_PATTERNS =" + "FILTER_PATTERNS = \"*/unreal/*=node ${PROJECT_BINARY_DIR}/blueprint_filter.js\"" + DOXYFILE2 ${DOXYFILE}) + string(REPLACE "HTML_EXTRA_STYLESHEET =" + "HTML_EXTRA_STYLESHEET = ${PROJECT_BINARY_DIR}/render.css " DOXYFILE + ${DOXYFILE2}) + file(WRITE "${PROJECT_BINARY_DIR}/Doxyfile" ${DOXYFILE}) + else() + configure_file("${PROJECT_SOURCE_DIR}/Doxyfile" "${PROJECT_BINARY_DIR}/Doxyfile" COPYONLY) + endif() + # "Build Doxygen documentation in ${PROJECT_SOURCE_DIR}/Documentation." "To view them you can + # for example use" "'python -m http.server -d \"${PROJECT_SOURCE_DIR}/Documentation\" 8080'" + # "'explorer http://localhost:8080/html'" + add_custom_target( + doc + ${DOXYGEN_EXECUTABLE} "${PROJECT_BINARY_DIR}/Doxyfile" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + COMMAND ${CMAKE_COMMAND} -E echo + COMMENT "Generate DoxygenDocumentation") + add_custom_command( + TARGET doc + POST_BUILD + COMMENT "" + COMMAND + ${CMAKE_COMMAND} -E cmake_echo_color --cyan + "Build Doxygen documentation in ${PROJECT_SOURCE_DIR}/Documentation." + "To view them you can for example use" "\" python -m http.server -d \\\"\ + ${PROJECT_SOURCE_DIR}/Documentation\\\" 8080\"" " explorer http://localhost:8080/html") - set(PY_HTML "${PROJECT_SOURCE_DIR}/Documentation/inkcpp_py.html") - if (INKCPP_PY) - find_package( - Python3 - REQUIRED - COMPONENTS Interpreter - ) - add_custom_target(inkcpp_py_doc - python -m pybind11_stubgen -o . inkcpp_py - COMMAND python -m pdoc -d google -o . inkcpp_py.pyi - COMMAND ${CMAKE_COMMAND} -E copy "./inkcpp_py.html" ${PY_HTML} - DEPENDS inkcpp_py - WORKING_DIRECTORY $ - COMMENT "Generates simple python documentation") - add_dependencies(doc inkcpp_py_doc) - else() - message(WARNING "The python target is disabled, therfore no python documentation will be build. Set INKCPP_PY to change this") - file(WRITE ${PY_HTML} "

Python Documenattion was not build!

") - endif(INKCPP_PY) -else(DOXYGEN_FOUND) - message("Doxygen needed to generate documntation!") -endif(DOXYGEN_FOUND) + set(PY_HTML "${PROJECT_SOURCE_DIR}/Documentation/inkcpp_py.html") + if(INKCPP_PY) + find_package(Python3 REQUIRED COMPONENTS Interpreter) + add_custom_target( + inkcpp_py_doc + python -m pybind11_stubgen -o . inkcpp_py + COMMAND python -m pdoc -d google -o . inkcpp_py.pyi + COMMAND ${CMAKE_COMMAND} -E copy "./inkcpp_py.html" ${PY_HTML} + DEPENDS inkcpp_py + WORKING_DIRECTORY $ + COMMENT "Generates simple python documentation") + add_dependencies(doc inkcpp_py_doc) + else() + message( + WARNING "The python target is disabled, therfore no python documentation will be build. \ + Set INKCPP_PY to change this") + file(WRITE ${PY_HTML} + "

Python Documenattion was not build!

") + endif(INKCPP_PY) + else(DOXYGEN_FOUND) + message("Doxygen needed to generate documntation!") + endif(DOXYGEN_FOUND) endif(NOT WHEEL_BUILD) diff --git a/inkcpp/include/runner.h b/inkcpp/include/runner.h index 68400d49..f9a647b4 100644 --- a/inkcpp/include/runner.h +++ b/inkcpp/include/runner.h @@ -76,6 +76,13 @@ class runner_interface */ virtual bool can_continue() const = 0; + /** + * @brief creates a snapshot containing the runner, globals and all other runners connected to the + * globals. + * @sa story::new_runner_from_snapshot, story::new_globals_from_snapshot + */ + virtual snapshot* create_snapshot() const = 0; + #ifdef INK_ENABLE_CSTD /** * Continue execution until the next newline, then allocate a c-style @@ -88,13 +95,7 @@ class runner_interface virtual const char* getline_alloc() = 0; #endif - /** - * @brief creates a snapshot containing the runner, globals and all other runners connected to the - * globals. - * @sa story::new_runner_from_snapshot, story::new_globals_from_snapshot - */ - virtual snapshot* create_snapshot() const = 0; - +#if defined(INK_ENABLE_STL) || defined(INK_ENABLE_UNREAL) /** * Execute the next line of the script. * @@ -114,6 +115,7 @@ class runner_interface * @return string with the next line of output */ virtual line_type getall() = 0; +#endif #ifdef INK_ENABLE_STL /** diff --git a/inkcpp/include/story_ptr.h b/inkcpp/include/story_ptr.h index ad4b4290..44c12c98 100644 --- a/inkcpp/include/story_ptr.h +++ b/inkcpp/include/story_ptr.h @@ -143,11 +143,10 @@ class story_ptr : public internal::story_ptr_base story_ptr cast() { // if cast fails, return null -#ifdef INK_ENABLE_UNREAL - // Unreal disables RTTI - U* casted = reinterpret_cast(_ptr); -#else +#ifdef INK_ENABLE_RTTI U* casted = dynamic_cast(_ptr); +#else + U* casted = reinterpret_cast(_ptr); #endif if (casted == nullptr) return nullptr; diff --git a/inkcpp/include/traits.h b/inkcpp/include/traits.h index e119a640..43f95bb9 100644 --- a/inkcpp/include/traits.h +++ b/inkcpp/include/traits.h @@ -101,9 +101,24 @@ struct remove_cv { typedef T type; }; +template +struct remove_reference { + typedef T type; +}; + +template +struct remove_reference { + typedef T type; +}; + +template +struct remove_reference { + typedef T type; +}; + template struct remove_cvref { - typedef std::remove_cv_t> type; + typedef typename remove_cv::type>::type type; }; // == string testing (from me) == @@ -140,21 +155,21 @@ template struct string_handler : string_handler { }; -#define MARK_AS_STRING(TYPE, LEN, SRC) \ - template<> \ - struct is_string : constant { \ - }; \ - template<> \ - struct string_handler { \ - static size_t length(const TYPE& x) { return static_cast(LEN); } \ - static void src_copy(const TYPE& x, char* output) \ - { \ - [&output](const char* src) { \ - while (*src != '\0') \ - *(output++) = *(src++); \ - *output = 0; \ - }(SRC); \ - } \ +#define MARK_AS_STRING(TYPE, LEN, SRC) \ + template<> \ + struct is_string : constant { \ + }; \ + template<> \ + struct string_handler { \ + static size_t length(const TYPE& x) { return static_cast(LEN); } \ + static void src_copy(const TYPE& x, char* output) \ + { \ + [&output](const char* src) { \ + while (*src != '\0') \ + *(output++) = *(src++); \ + *output = 0; \ + }(SRC); \ + } \ } inline size_t c_str_len(const char* c) diff --git a/inkcpp/list_table.h b/inkcpp/list_table.h index 9139f6a6..1740d9b8 100644 --- a/inkcpp/list_table.h +++ b/inkcpp/list_table.h @@ -263,14 +263,12 @@ class list_table : public snapshot_interface const data_t* getPtr(int eid) const { - return _data.begin() - + static_cast(_entrySize) * static_cast(eid); + return _data.begin() + static_cast(_entrySize) * static_cast(eid); } data_t* getPtr(int eid) { - return _data.begin() - + static_cast(_entrySize) * static_cast(eid); + return _data.begin() + static_cast(_entrySize) * static_cast(eid); } int numFlags() const diff --git a/inkcpp/runner_impl.cpp b/inkcpp/runner_impl.cpp index 05ab406b..05be3fd7 100644 --- a/inkcpp/runner_impl.cpp +++ b/inkcpp/runner_impl.cpp @@ -505,6 +505,8 @@ runner_impl::~runner_impl() } } +#if defined(INK_ENABLE_STL) || defined(INK_ENABLE_UNREAL) + runner_impl::line_type runner_impl::getline() { // Advance interpreter one line and write to output @@ -545,6 +547,8 @@ runner_impl::line_type runner_impl::getall() return result; } +#endif + #ifdef INK_ENABLE_STL void runner_impl::getline(std::ostream& out) { out << getline(); } @@ -864,7 +868,7 @@ bool runner_impl::line_step() void runner_impl::step() { -#ifndef INK_ENABLE_UNREAL +#ifdef INK_ENABLE_EH try #endif { @@ -1496,7 +1500,7 @@ void runner_impl::step() } #endif } -#ifndef INK_ENABLE_UNREAL +#ifdef INK_ENABLE_EH catch (...) { // Reset our whole state as it's probably corrupt reset(); diff --git a/inkcpp/runner_impl.h b/inkcpp/runner_impl.h index 26f4e44a..7cf61d32 100644 --- a/inkcpp/runner_impl.h +++ b/inkcpp/runner_impl.h @@ -132,11 +132,13 @@ class runner_impl // move to path virtual bool move_to(hash_t path) override; +#if defined(INK_ENABLE_STL) || defined(INK_ENABLE_UNREAL) // Gets a single line of output virtual line_type getline() override; // get all into string virtual line_type getall() override; +#endif #ifdef INK_ENABLE_STL // Reads a line into a std::ostream diff --git a/shared/public/config.h b/shared/public/config.h index 4bb0877f..e2d14ea4 100644 --- a/shared/public/config.h +++ b/shared/public/config.h @@ -6,8 +6,11 @@ */ #pragma once +// The UE build process will define INKCPP_API #ifdef INKCPP_API # define INK_ENABLE_UNREAL +# define INKCPP_NO_EH +# define INKCPP_NO_RTTI #elif INKCPP_BUILD_CLIB # define INK_ENABLE_CSTD #else @@ -15,6 +18,14 @@ # define INK_ENABLE_CSTD #endif +#ifndef INKCPP_NO_EH +# define INK_ENABLE_EH +#endif + +#ifndef INKCPP_NO_RTTI +# define INK_ENABLE_RTTI +#endif + // Only turn on if you have json.hpp and you want to use it with the compiler // #define INK_EXPOSE_JSON diff --git a/shared/public/system.h b/shared/public/system.h index d1b70816..25040751 100644 --- a/shared/public/system.h +++ b/shared/public/system.h @@ -13,7 +13,6 @@ # include "Misc/CString.h" # include "HAL/UnrealMemory.h" # include "Hash/CityHash.h" - #endif #ifdef INK_ENABLE_STL # include @@ -24,6 +23,9 @@ # include # include #endif +#ifdef INK_ENABLE_CSTD +# include +#endif // Platform specific defines // @@ -46,6 +48,17 @@ namespace ink */ typedef unsigned int uint32_t; +#ifndef INK_ENABLE_STL + +/** Additional signed integer types */ +typedef int int32_t; +typedef short int16_t; + +/** Additional unsigned integer types */ +typedef unsigned long long uint64_t; +typedef unsigned short uint16_t; +#endif // ndef INK_ENABLE_STL + /** Name hash (used for temporary variables) */ typedef uint32_t hash_t; @@ -65,6 +78,18 @@ hash_t hash_string(const char* string); /** Byte type */ typedef unsigned char byte_t; +/** Ptr difference type */ +typedef decltype(static_cast(nullptr) - static_cast(nullptr)) ptrdiff_t; + +/** Verify sizes */ +static_assert(sizeof(byte_t) == 1); +static_assert(sizeof(uint16_t) == 2); +static_assert(sizeof(int16_t) == 2); +static_assert(sizeof(uint32_t) == 4); +static_assert(sizeof(int32_t) == 4); +static_assert(sizeof(uint64_t) == 8); +static_assert(sizeof(ptrdiff_t) == sizeof(void*)); + /** Used to identify an offset in a data table (like a string in the string table) */ typedef uint32_t offset_t;