diff --git a/sol/stack_push.hpp b/sol/stack_push.hpp index 1e74ea24..48a8d24b 100644 --- a/sol/stack_push.hpp +++ b/sol/stack_push.hpp @@ -1,4 +1,4 @@ -// sol2 +// sol2 // The MIT License (MIT) @@ -37,6 +37,7 @@ #include #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #include +#include #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT #include #endif // Can use variant @@ -613,7 +614,7 @@ namespace stack { template struct pusher { static int push(lua_State* L, const char (&str)[N]) { - lua_pushlstring(L, str, N - 1); + lua_pushlstring(L, str, std::char_traits::length(str)); return 1; } @@ -892,7 +893,7 @@ namespace stack { template struct pusher { static int push(lua_State* L, const wchar_t (&str)[N]) { - return push(L, str, N - 1); + return push(L, str, std::char_traits::length(str)); } static int push(lua_State* L, const wchar_t (&str)[N], std::size_t sz) { @@ -903,7 +904,7 @@ namespace stack { template struct pusher { static int push(lua_State* L, const char16_t (&str)[N]) { - return push(L, str, N - 1); + return push(L, str, std::char_traits::length(str)); } static int push(lua_State* L, const char16_t (&str)[N], std::size_t sz) { @@ -914,7 +915,7 @@ namespace stack { template struct pusher { static int push(lua_State* L, const char32_t (&str)[N]) { - return push(L, str, N - 1); + return push(L, str, std::char_traits::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 + struct pusher> { + template + static int push(lua_State* L, T&& t) { + if (t == std::nullopt) { + return stack::push(L, nullopt); + } + return stack::push(L, static_cast::value, O&, O&&>>(t.value())); + } + }; + #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT namespace stack_detail {