Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,16 @@ set(INKCPP_INKLECATE
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)
option(INKCPP_NO_EXCEPTIONS "Used to build without support for exceptions, disables try/catch blocks and throws" OFF)

if(INKCPP_NO_EH)
add_definitions(-DINKCPP_NO_EH)
endif()
if(INKCPP_NO_RTTI)
add_definitions(-DINKCPP_NO_RTTI)
endif()

if(INKCPP_NO_EXCEPTIONS)
add_definitions(-DINKCPP_NO_EXCEPTIONS)
endif()
string(TOUPPER "${INKCPP_INKLECATE}" inkcpp_inklecate_upper)
if(inkcpp_inklecate_upper STREQUAL "ALL")
FetchContent_MakeAvailable(inklecate_windows inklecate_mac inklecate_linux)
Expand Down
4 changes: 2 additions & 2 deletions inkcpp/runner_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ bool runner_impl::line_step()

void runner_impl::step()
{
#ifdef INK_ENABLE_EH
#ifdef INK_ENABLE_EXCEPTIONS
try
#endif
{
Expand Down Expand Up @@ -1500,7 +1500,7 @@ void runner_impl::step()
}
#endif
}
#ifdef INK_ENABLE_EH
#ifdef INK_ENABLE_EXCEPTIONS
catch (...) {
// Reset our whole state as it's probably corrupt
reset();
Expand Down
4 changes: 2 additions & 2 deletions inkcpp/snapshot_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ snapshot* snapshot::from_file(const char* filename)
{
std::ifstream ifs(filename, std::ios::binary | std::ios::ate);
if (! ifs.is_open()) {
throw ink_exception("Failed to open snapshot file: " + std::string(filename));
ink_assert(false, "Failed to open snapshot file: %s", filename);
}

size_t length = static_cast<size_t>(ifs.tellg());
Expand All @@ -43,7 +43,7 @@ void snapshot::write_to_file(const char* filename) const
{
std::ofstream ofs(filename, std::ios::binary);
if (! ofs.is_open()) {
throw ink_exception("Failed to open file to write snapshot: " + std::string(filename));
ink_assert(false, "Failed to open file to write snapshot: %s", filename);
}
ofs.write(reinterpret_cast<const char*>(get_data()), get_data_len());
}
Expand Down
2 changes: 1 addition & 1 deletion inkcpp/story_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ unsigned char* read_file_into_memory(const char* filename, size_t* read)
ifstream ifs(filename, ios::binary | ios::ate);

if (! ifs.is_open()) {
throw ink_exception("Failed to open file: " + std::string(filename));
ink_assert(false, "Failed to open file: %s", filename);
}

ifstream::pos_type pos = ifs.tellg();
Expand Down
2 changes: 1 addition & 1 deletion inkcpp/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void append<value_type::boolean>(std::ostream& os, const value& val, const list_
std::ostream& value::write(std::ostream& os, const list_table* lists) const
{
if (type() < value_type::PRINT_BEGIN || type() >= value_type::PRINT_END) {
throw ink_exception("printing this type is not supported");
ink_assert(false, "printing this type is not supported");
}
append(os, *this, lists);
return os;
Expand Down
10 changes: 5 additions & 5 deletions shared/public/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
// The UE build process will define INKCPP_API
#ifdef INKCPP_API
# define INK_ENABLE_UNREAL
# define INKCPP_NO_EH
# define INKCPP_NO_RTTI
# define INKCPP_NO_EXCEPTIONS
#elif INKCPP_BUILD_CLIB
# define INK_ENABLE_CSTD
#else
# define INK_ENABLE_STL
# define INK_ENABLE_CSTD
#endif

#ifndef INKCPP_NO_EH
# define INK_ENABLE_EH
#endif

#ifndef INKCPP_NO_RTTI
# define INK_ENABLE_RTTI
#endif

#ifndef INKCPP_NO_EXCEPTIONS
# define INK_ENABLE_EXCEPTIONS
#endif

// Only turn on if you have json.hpp and you want to use it with the compiler
// #define INK_EXPOSE_JSON

Expand Down
35 changes: 24 additions & 11 deletions shared/public/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
# include "Hash/CityHash.h"
#endif
#ifdef INK_ENABLE_STL
# include <exception>
# ifdef INK_ENABLE_EXCEPTIONS
# include <exception>
# endif
# include <stdexcept>
# include <optional>
# include <cctype>
Expand All @@ -30,17 +32,21 @@
// Platform specific defines //

#ifdef INK_ENABLE_UNREAL
# define inkZeroMemory(buff, len) FMemory::Memset(buff, 0, len)
# define inkAssert(condition, text, ...) checkf(condition, TEXT(text), ##__VA_ARGS__)
# define inkFail(text, ...) checkf(false, TEXT(text), ##__VA_ARGS__)
# define FORMAT_STRING_STR "%hs"
# define inkZeroMemory(buff, len) FMemory::Memset(buff, 0, len)
# define FORMAT_STRING_STR "%hs"
#else
# define inkZeroMemory ink::internal::zero_memory
# define inkAssert ink::ink_assert
# define inkFail(...) ink::ink_assert(false, __VA_ARGS__)
# define FORMAT_STRING_STR "%s"
#endif

#ifdef INK_ENABLE_UNREAL
# define inkAssert(condition, text, ...) checkf(condition, TEXT(text), ##__VA_ARGS__)
# define inkFail(text, ...) checkf(false, TEXT(text), ##__VA_ARGS__)
#else
# define inkAssert ink::ink_assert
# define inkFail(...) ink::ink_assert(false, __VA_ARGS__)
#endif

namespace ink
{
/** define basic numeric type
Expand Down Expand Up @@ -175,7 +181,7 @@ namespace internal
#endif
} // namespace internal

#ifdef INK_ENABLE_STL
#ifdef INK_ENABLE_EXCEPTIONS
/** exception type thrown if something goes wrong */
using ink_exception = std::runtime_error;
#else
Expand Down Expand Up @@ -209,10 +215,17 @@ void ink_assert(bool condition, const char* msg = nullptr, Args... args)
size_t size = snprintf(nullptr, 0, msg, args...) + 1;
char* message = static_cast<char*>(malloc(size));
snprintf(message, size, msg, args...);
throw ink_exception(message);
} else {
throw ink_exception(msg);
msg = message;
}

# ifdef INK_ENABLE_EXCEPTIONS
throw ink_exception(msg);
# elif defined(INK_ENABLE_CSTD)
fprintf(stderr, "Ink Assert: %s\n", msg);
abort();
# else
# error "This path needs a way to warn and then terminate, otherwise it'll silently fail"
# endif
}
}

Expand Down
Loading