C and C++ strings are ass

This commit is contained in:
ThePhD 2018-11-20 22:09:43 -05:00
parent 93db30d200
commit 157db07a56
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA

View File

@ -1,4 +1,4 @@
// sol2
// sol2
// The MIT License (MIT)
@ -37,6 +37,7 @@
#include <limits>
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <string_view>
#include <optional>
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
#include <variant>
#endif // Can use variant
@ -613,7 +614,7 @@ namespace stack {
template <size_t N>
struct pusher<char[N]> {
static int push(lua_State* L, const char (&str)[N]) {
lua_pushlstring(L, str, N - 1);
lua_pushlstring(L, str, std::char_traits<char>::length(str));
return 1;
}
@ -892,7 +893,7 @@ namespace stack {
template <size_t N>
struct pusher<wchar_t[N]> {
static int push(lua_State* L, const wchar_t (&str)[N]) {
return push(L, str, N - 1);
return push(L, str, std::char_traits<wchar_t>::length(str));
}
static int push(lua_State* L, const wchar_t (&str)[N], std::size_t sz) {
@ -903,7 +904,7 @@ namespace stack {
template <size_t N>
struct pusher<char16_t[N]> {
static int push(lua_State* L, const char16_t (&str)[N]) {
return push(L, str, N - 1);
return push(L, str, std::char_traits<char16_t>::length(str));
}
static int push(lua_State* L, const char16_t (&str)[N], std::size_t sz) {
@ -914,7 +915,7 @@ namespace stack {
template <size_t N>
struct pusher<char32_t[N]> {
static int push(lua_State* L, const char32_t (&str)[N]) {
return push(L, str, N - 1);
return push(L, str, std::char_traits<char32_t>::length(str));
}
static int push(lua_State* L, const char32_t (&str)[N], std::size_t sz) {
@ -1030,6 +1031,17 @@ namespace stack {
};
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename O>
struct pusher<std::optional<O>> {
template <typename T>
static int push(lua_State* L, T&& t) {
if (t == std::nullopt) {
return stack::push(L, nullopt);
}
return stack::push(L, static_cast<std::conditional_t<std::is_lvalue_reference<T>::value, O&, O&&>>(t.value()));
}
};
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
namespace stack_detail {