mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
C and C++ strings are ass
This commit is contained in:
parent
93db30d200
commit
157db07a56
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user