beep boop fixes

This commit is contained in:
ThePhD 2018-11-21 15:03:45 -05:00
parent 55e92056c1
commit 4906e43918
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
5 changed files with 78 additions and 10 deletions

View File

@ -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 2018-11-21 12:34:11.276133 UTC
// This header was generated with sol v2.20.5 (revision 157db07)
// Generated 2018-11-21 20:02:05.860519 UTC
// This header was generated with sol v2.20.5 (revision 55e9205)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP
@ -4618,6 +4618,7 @@ namespace sol {
// end of sol/filters.hpp
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <optional>
#ifdef SOL_STD_VARIANT
#include <variant>
#endif
@ -5574,6 +5575,9 @@ namespace sol {
template <typename T>
struct lua_type_of<optional<T>> : std::integral_constant<type, type::poly> {};
template <typename T>
struct lua_type_of<std::optional<T>> : std::integral_constant<type, type::poly> {};
template <>
struct lua_type_of<variadic_args> : std::integral_constant<type, type::poly> {};
@ -7148,7 +7152,6 @@ namespace sol {
#include <forward_list>
#include <algorithm>
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <optional>
#endif // C++17
namespace sol {
@ -8157,8 +8160,8 @@ namespace sol {
// beginning of sol/stack_check_unqualified.hpp
#include <cmath>
#ifdef SOL_CXX17_FEATURES
#ifdef SOL_STD_VARIANT
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
#endif // SOL_STD_VARIANT
#endif // SOL_CXX17_FEATURES
@ -8734,7 +8737,26 @@ namespace stack {
};
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename T, typename C>
struct checker<std::optional<T>, type::poly, C> {
template <typename Handler>
static bool check(lua_State* L, int index, Handler&&, record& tracking) {
type t = type_of(L, index);
if (t == type::none) {
tracking.use(0);
return true;
}
if (t == type::lua_nil) {
tracking.use(1);
return true;
}
return stack::check<T>(L, index, no_panic, tracking);
}
};
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
template <typename... Tn, typename C>
struct checker<std::variant<Tn...>, type::poly, C> {
typedef std::variant<Tn...> V;
@ -8765,7 +8787,9 @@ namespace stack {
return is_one(std::integral_constant<std::size_t, V_size::value>(), L, index, std::forward<Handler>(handler), tracking);
}
};
#endif // SOL_STD_VARIANT
#endif // SOL_CXX17_FEATURES
}
} // namespace sol::stack

View File

@ -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 2018-11-21 12:34:11.544452 UTC
// This header was generated with sol v2.20.5 (revision 157db07)
// Generated 2018-11-21 20:02:06.079930 UTC
// This header was generated with sol v2.20.5 (revision 55e9205)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP

View File

@ -31,8 +31,9 @@
#include <functional>
#include <utility>
#include <cmath>
#ifdef SOL_CXX17_FEATURES
#ifdef SOL_STD_VARIANT
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <optional>
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
#include <variant>
#endif // SOL_STD_VARIANT
#endif // SOL_CXX17_FEATURES
@ -609,7 +610,26 @@ namespace stack {
};
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename T, typename C>
struct checker<std::optional<T>, type::poly, C> {
template <typename Handler>
static bool check(lua_State* L, int index, Handler&&, record& tracking) {
type t = type_of(L, index);
if (t == type::none) {
tracking.use(0);
return true;
}
if (t == type::lua_nil) {
tracking.use(1);
return true;
}
return stack::check<T>(L, index, no_panic, tracking);
}
};
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
template <typename... Tn, typename C>
struct checker<std::variant<Tn...>, type::poly, C> {
typedef std::variant<Tn...> V;
@ -640,7 +660,9 @@ namespace stack {
return is_one(std::integral_constant<std::size_t, V_size::value>(), L, index, std::forward<Handler>(handler), tracking);
}
};
#endif // SOL_STD_VARIANT
#endif // SOL_CXX17_FEATURES
}
} // namespace sol::stack

View File

@ -39,6 +39,7 @@
#include <string>
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <string_view>
#include <optional>
#ifdef SOL_STD_VARIANT
#include <variant>
#endif
@ -995,6 +996,9 @@ namespace sol {
template <typename T>
struct lua_type_of<optional<T>> : std::integral_constant<type, type::poly> {};
template <typename T>
struct lua_type_of<std::optional<T>> : std::integral_constant<type, type::poly> {};
template <>
struct lua_type_of<variadic_args> : std::integral_constant<type, type::poly> {};

View File

@ -36,7 +36,6 @@
std::mutex basic_init_require_mutex;
void basic_initialization_and_lib_open() {
sol::state lua;
try {
lua.open_libraries();
@ -149,6 +148,25 @@ TEST_CASE("utility/optional", "test that shit optional can be round-tripped") {
REQUIRE_FALSE(result.valid());
};
}
SECTION("in classes") {
sol::state lua;
lua.open_libraries(sol::lib::base);
struct opt_c {
std::optional<int> member;
};
auto uto = lua.new_usertype<opt_c>("opt_c",
"value", &opt_c::member);
opt_c obj;
lua["obj"] = std::ref(obj);
lua.safe_script("print(obj.value) obj.value = 20 print(obj.value)");
REQUIRE(obj.member == 20);
lua.safe_script("print(obj.value) obj.value = nil print(obj.value)");
REQUIRE(obj.member == std::nullopt);
}
#else
REQUIRE(true);
#endif // C++17