From 0d1d5ebd09d541bafff652fad7eb1d8bb1ab9e2c Mon Sep 17 00:00:00 2001 From: ThePhD Date: Fri, 12 Aug 2016 13:08:59 -0400 Subject: [PATCH] Turns out C++ sucks when all implementers don't do things equally as fast. WHO KNEW? --- docs/source/codecvt.rst | 8 ++++++++ docs/source/index.rst | 3 ++- single/sol/sol.hpp | 21 +++++++++++++++++++-- sol/compatibility/version.hpp | 15 +++++++++++++++ sol/stack_get.hpp | 4 ++++ sol/stack_push.hpp | 4 ++++ test_strings.cpp | 3 ++- 7 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 docs/source/codecvt.rst diff --git a/docs/source/codecvt.rst b/docs/source/codecvt.rst new file mode 100644 index 00000000..38b57245 --- /dev/null +++ b/docs/source/codecvt.rst @@ -0,0 +1,8 @@ +std::(w/u16/u32)string support +============================== +because this is surprisingly hard using standard C++ +---------------------------------------------------- + +Individuals using Visual Studio 2015, or on Windows with the VC++ and MinGW compilers (possibly Clang++ on Windows as well) have ```` headers, and thusly Sol will attempt to include it. Individuals on GC 4.9.x, Clang 3.5.x, Clang 3.6.x do not seem to have ```` shipped with the standard library that comes with installation of these compilers. If you want ``std::wstring``, ``std::u16string``, ``std::u32string`` automatic handling then you need to make sure you have those headers and then define ``SOL_CODECVT_SUPPORT``. + +ThePhD did not want this to have to be a thing, but slow implementations and such force my hand. When GCC 7.x comes out, ThePhD will consider removing the effect of defining this macro and leaving support in at all times. diff --git a/docs/source/index.rst b/docs/source/index.rst index 1a00a665..f3eebcfe 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -7,7 +7,7 @@ :target: https://github.com/ThePhD/sol2 :alt: sol2 repository -Sol 2.10 +Sol 2.11 ======== a fast, simple C++ and Lua Binding ---------------------------------- @@ -34,6 +34,7 @@ get going: safety exceptions rtti + codecvt cmake licenses origin diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 7ff871a8..baff60e3 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2016-08-12 16:30:43.996035 UTC -// This header was generated with sol v2.11.3 (revision ffdff21) +// Generated 2016-08-12 17:00:49.377996 UTC +// This header was generated with sol v2.11.3 (revision cd64453) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -1785,6 +1785,19 @@ namespace sol { #include +#if defined(_WIN32) || defined(_MSC_VER) +#ifndef SOL_CODECVT_SUPPORT +#define SOL_CODECVT_SUPPORT 1 +#endif // codecvt support +#elif defined(__GNUC__) +#if __GNUC__ == 5 +#ifndef SOL_CODECVT_SUPPORT +#define SOL_CODECVT_SUPPORT 1 +#endif // codecvt support +#endif // g++ 5.x.x +#else +#endif // Windows/VC++ vs. g++ vs Others + #ifdef LUAJIT_VERSION #ifndef SOL_LUAJIT #define SOL_LUAJIT @@ -4927,6 +4940,7 @@ namespace sol { } }; +#ifdef SOL_CODECVT_SUPPORT template<> struct getter { static std::wstring get(lua_State* L, int index, record& tracking) { @@ -5017,6 +5031,7 @@ namespace sol { return str.size() > 0 ? str[0] : '\0'; } }; +#endif // codecvt Header Support template<> struct getter { @@ -5745,6 +5760,7 @@ namespace sol { } }; +#ifdef SOL_CODECVT_SUPPORT template<> struct pusher { static int push(lua_State* L, const wchar_t* wstr) { @@ -5905,6 +5921,7 @@ namespace sol { return stack::push(L, u32str.data(), u32str.data() + sz); } }; +#endif // Codecvt Header Support template struct pusher> { diff --git a/sol/compatibility/version.hpp b/sol/compatibility/version.hpp index 8d590413..e7c1947d 100644 --- a/sol/compatibility/version.hpp +++ b/sol/compatibility/version.hpp @@ -24,6 +24,21 @@ #include +#if defined(_WIN32) || defined(_MSC_VER) +#ifndef SOL_CODECVT_SUPPORT +#define SOL_CODECVT_SUPPORT 1 +#endif // codecvt support +#elif defined(__GNUC__) +#if __GNUC__ >= 5 +#ifndef SOL_CODECVT_SUPPORT +#define SOL_CODECVT_SUPPORT 1 +#endif // codecvt support +#endif // g++ 5.x.x +#else +// Clang sucks and doesn't really utilize codecvt support, +// not without checking the library versions explicitly (and we're not gonna do that, so fuck you) +#endif // Windows/VC++ vs. g++ vs Others + #ifdef LUAJIT_VERSION #ifndef SOL_LUAJIT #define SOL_LUAJIT diff --git a/sol/stack_get.hpp b/sol/stack_get.hpp index 6e290767..fa08fd09 100644 --- a/sol/stack_get.hpp +++ b/sol/stack_get.hpp @@ -30,8 +30,10 @@ #include #include #include +#ifdef SOL_CODECVT_SUPPORT #include #include +#endif namespace sol { namespace stack { @@ -177,6 +179,7 @@ namespace sol { } }; +#ifdef SOL_CODECVT_SUPPORT template<> struct getter { static std::wstring get(lua_State* L, int index, record& tracking) { @@ -267,6 +270,7 @@ namespace sol { return str.size() > 0 ? str[0] : '\0'; } }; +#endif // codecvt Header Support template<> struct getter { diff --git a/sol/stack_push.hpp b/sol/stack_push.hpp index 47ef1735..647eafae 100644 --- a/sol/stack_push.hpp +++ b/sol/stack_push.hpp @@ -26,8 +26,10 @@ #include "raii.hpp" #include "optional.hpp" #include +#ifdef SOL_CODECVT_SUPPORT #include #include +#endif namespace sol { namespace stack { @@ -401,6 +403,7 @@ namespace sol { } }; +#ifdef SOL_CODECVT_SUPPORT template<> struct pusher { static int push(lua_State* L, const wchar_t* wstr) { @@ -561,6 +564,7 @@ namespace sol { return stack::push(L, u32str.data(), u32str.data() + sz); } }; +#endif // Codecvt Header Support template struct pusher> { diff --git a/test_strings.cpp b/test_strings.cpp index 1f26c010..429f7b4b 100644 --- a/test_strings.cpp +++ b/test_strings.cpp @@ -32,7 +32,7 @@ TEST_CASE("stack/strings", "test that strings can be roundtripped") { static const std::u32string utf32str_s = utf32str; static const std::wstring widestr_s = widestr; - +#ifdef SOL_CODECVT_SUPPORT lua["utf8"] = utf8str; lua["utf16"] = utf16str; lua["utf32"] = utf32str; @@ -87,6 +87,7 @@ TEST_CASE("stack/strings", "test that strings can be roundtripped") { REQUIRE(utf16_to_char32 == utf32str[0]); REQUIRE(utf32_to_char32 == utf32str[0]); REQUIRE(wide_to_char32 == utf32str[0]); +#endif // codecvt support } TEST_CASE("detail/demangling", "test some basic demangling cases") {