Turns out C++ sucks when all implementers don't do things equally as fast. WHO KNEW?

This commit is contained in:
ThePhD 2016-08-12 13:08:59 -04:00
parent cd64453789
commit 0d1d5ebd09
7 changed files with 54 additions and 4 deletions

8
docs/source/codecvt.rst Normal file
View File

@ -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 ``<codecvt>`` 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 ``<codecvt>`` 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 <codecvt> support in at all times.

View File

@ -7,7 +7,7 @@
:target: https://github.com/ThePhD/sol2 :target: https://github.com/ThePhD/sol2
:alt: sol2 repository :alt: sol2 repository
Sol 2.10 Sol 2.11
======== ========
a fast, simple C++ and Lua Binding a fast, simple C++ and Lua Binding
---------------------------------- ----------------------------------
@ -34,6 +34,7 @@ get going:
safety safety
exceptions exceptions
rtti rtti
codecvt
cmake cmake
licenses licenses
origin origin

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2016-08-12 16:30:43.996035 UTC // Generated 2016-08-12 17:00:49.377996 UTC
// This header was generated with sol v2.11.3 (revision ffdff21) // This header was generated with sol v2.11.3 (revision cd64453)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP #ifndef SOL_SINGLE_INCLUDE_HPP
@ -1785,6 +1785,19 @@ namespace sol {
#include <lua.hpp> #include <lua.hpp>
#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 #ifdef LUAJIT_VERSION
#ifndef SOL_LUAJIT #ifndef SOL_LUAJIT
#define SOL_LUAJIT #define SOL_LUAJIT
@ -4927,6 +4940,7 @@ namespace sol {
} }
}; };
#ifdef SOL_CODECVT_SUPPORT
template<> template<>
struct getter<std::wstring> { struct getter<std::wstring> {
static std::wstring get(lua_State* L, int index, record& tracking) { static std::wstring get(lua_State* L, int index, record& tracking) {
@ -5017,6 +5031,7 @@ namespace sol {
return str.size() > 0 ? str[0] : '\0'; return str.size() > 0 ? str[0] : '\0';
} }
}; };
#endif // codecvt Header Support
template<> template<>
struct getter<meta_function> { struct getter<meta_function> {
@ -5745,6 +5760,7 @@ namespace sol {
} }
}; };
#ifdef SOL_CODECVT_SUPPORT
template<> template<>
struct pusher<const wchar_t*> { struct pusher<const wchar_t*> {
static int push(lua_State* L, const wchar_t* wstr) { 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); return stack::push(L, u32str.data(), u32str.data() + sz);
} }
}; };
#endif // Codecvt Header Support
template<typename... Args> template<typename... Args>
struct pusher<std::tuple<Args...>> { struct pusher<std::tuple<Args...>> {

View File

@ -24,6 +24,21 @@
#include <lua.hpp> #include <lua.hpp>
#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 #ifdef LUAJIT_VERSION
#ifndef SOL_LUAJIT #ifndef SOL_LUAJIT
#define SOL_LUAJIT #define SOL_LUAJIT

View File

@ -30,8 +30,10 @@
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <utility> #include <utility>
#ifdef SOL_CODECVT_SUPPORT
#include <codecvt> #include <codecvt>
#include <locale> #include <locale>
#endif
namespace sol { namespace sol {
namespace stack { namespace stack {
@ -177,6 +179,7 @@ namespace sol {
} }
}; };
#ifdef SOL_CODECVT_SUPPORT
template<> template<>
struct getter<std::wstring> { struct getter<std::wstring> {
static std::wstring get(lua_State* L, int index, record& tracking) { static std::wstring get(lua_State* L, int index, record& tracking) {
@ -267,6 +270,7 @@ namespace sol {
return str.size() > 0 ? str[0] : '\0'; return str.size() > 0 ? str[0] : '\0';
} }
}; };
#endif // codecvt Header Support
template<> template<>
struct getter<meta_function> { struct getter<meta_function> {

View File

@ -26,8 +26,10 @@
#include "raii.hpp" #include "raii.hpp"
#include "optional.hpp" #include "optional.hpp"
#include <memory> #include <memory>
#ifdef SOL_CODECVT_SUPPORT
#include <codecvt> #include <codecvt>
#include <locale> #include <locale>
#endif
namespace sol { namespace sol {
namespace stack { namespace stack {
@ -401,6 +403,7 @@ namespace sol {
} }
}; };
#ifdef SOL_CODECVT_SUPPORT
template<> template<>
struct pusher<const wchar_t*> { struct pusher<const wchar_t*> {
static int push(lua_State* L, const wchar_t* wstr) { 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); return stack::push(L, u32str.data(), u32str.data() + sz);
} }
}; };
#endif // Codecvt Header Support
template<typename... Args> template<typename... Args>
struct pusher<std::tuple<Args...>> { struct pusher<std::tuple<Args...>> {

View File

@ -32,7 +32,7 @@ TEST_CASE("stack/strings", "test that strings can be roundtripped") {
static const std::u32string utf32str_s = utf32str; static const std::u32string utf32str_s = utf32str;
static const std::wstring widestr_s = widestr; static const std::wstring widestr_s = widestr;
#ifdef SOL_CODECVT_SUPPORT
lua["utf8"] = utf8str; lua["utf8"] = utf8str;
lua["utf16"] = utf16str; lua["utf16"] = utf16str;
lua["utf32"] = utf32str; lua["utf32"] = utf32str;
@ -87,6 +87,7 @@ TEST_CASE("stack/strings", "test that strings can be roundtripped") {
REQUIRE(utf16_to_char32 == utf32str[0]); REQUIRE(utf16_to_char32 == utf32str[0]);
REQUIRE(utf32_to_char32 == utf32str[0]); REQUIRE(utf32_to_char32 == utf32str[0]);
REQUIRE(wide_to_char32 == utf32str[0]); REQUIRE(wide_to_char32 == utf32str[0]);
#endif // codecvt support
} }
TEST_CASE("detail/demangling", "test some basic demangling cases") { TEST_CASE("detail/demangling", "test some basic demangling cases") {