mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
proxy testing
This commit is contained in:
parent
5b3ca9343c
commit
88a089c4ae
|
@ -91,7 +91,7 @@ namespace sol { namespace detail {
|
||||||
}} // namespace sol::detail
|
}} // namespace sol::detail
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) tl::detail::is_trivially_copy_constructible<T>::value
|
#define SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) sol::detail::is_trivially_copy_constructible<T>::value
|
||||||
#define SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE(T) std::is_trivially_copy_assignable<T>::value
|
#define SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE(T) std::is_trivially_copy_assignable<T>::value
|
||||||
#define SOL_TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE(T) std::is_trivially_destructible<T>::value
|
#define SOL_TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE(T) std::is_trivially_destructible<T>::value
|
||||||
#else
|
#else
|
||||||
|
@ -220,7 +220,7 @@ namespace sol {
|
||||||
template <class... Ts>
|
template <class... Ts>
|
||||||
using void_t = typename voider<Ts...>::type;
|
using void_t = typename voider<Ts...>::type;
|
||||||
|
|
||||||
// Trait for checking if a type is a tl::optional
|
// Trait for checking if a type is a sol::optional
|
||||||
template <class T>
|
template <class T>
|
||||||
struct is_optional_impl : std::false_type {};
|
struct is_optional_impl : std::false_type {};
|
||||||
template <class T>
|
template <class T>
|
||||||
|
@ -228,7 +228,7 @@ namespace sol {
|
||||||
template <class T>
|
template <class T>
|
||||||
using is_optional = is_optional_impl<decay_t<T>>;
|
using is_optional = is_optional_impl<decay_t<T>>;
|
||||||
|
|
||||||
// Change void to tl::monostate
|
// Change void to sol::monostate
|
||||||
template <class U>
|
template <class U>
|
||||||
using fixup_void = conditional_t<std::is_void<U>::value, monostate, U>;
|
using fixup_void = conditional_t<std::is_void<U>::value, monostate, U>;
|
||||||
|
|
||||||
|
@ -644,9 +644,9 @@ namespace sol {
|
||||||
///
|
///
|
||||||
/// *Examples*:
|
/// *Examples*:
|
||||||
/// ```
|
/// ```
|
||||||
/// tl::optional<int> a = tl::nullopt;
|
/// sol::optional<int> a = sol::nullopt;
|
||||||
/// void foo (tl::optional<int>);
|
/// void foo (sol::optional<int>);
|
||||||
/// foo(tl::nullopt); //pass an empty optional
|
/// foo(sol::nullopt); //pass an empty optional
|
||||||
/// ```
|
/// ```
|
||||||
static constexpr nullopt_t nullopt{ nullopt_t::do_not_use{}, nullopt_t::do_not_use{} };
|
static constexpr nullopt_t nullopt{ nullopt_t::do_not_use{}, nullopt_t::do_not_use{} };
|
||||||
|
|
||||||
|
@ -1652,7 +1652,7 @@ namespace sol {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// int i = 42;
|
/// int i = 42;
|
||||||
/// tl::optional<int&> o = i;
|
/// sol::optional<int&> o = i;
|
||||||
/// *o == 42; //true
|
/// *o == 42; //true
|
||||||
/// i = 12;
|
/// i = 12;
|
||||||
/// *o = 12; //true
|
/// *o = 12; //true
|
||||||
|
|
|
@ -184,7 +184,7 @@ namespace sol {
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy& force() {
|
proxy& force() {
|
||||||
if (this->valid()) {
|
if (!this->valid()) {
|
||||||
this->set(new_table());
|
this->set(new_table());
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
@ -97,3 +97,15 @@ TEST_CASE("proxy/equality", "check to make sure equality tests work") {
|
||||||
REQUIRE_FALSE((lua["a"] != 2));
|
REQUIRE_FALSE((lua["a"] != 2));
|
||||||
#endif // clang screws up by trying to access int128 types that it doesn't support, even when we don't ask for them
|
#endif // clang screws up by trying to access int128 types that it doesn't support, even when we don't ask for them
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("proxy/force", "allow proxies to force creation of tables") {
|
||||||
|
sol::state lua;
|
||||||
|
lua.open_libraries(sol::lib::base, sol::lib::io);
|
||||||
|
|
||||||
|
sol::optional<int> not_there = lua["a"]["b"]["c"];
|
||||||
|
REQUIRE_FALSE(static_cast<bool>(not_there));
|
||||||
|
lua["a"].force()["b"].force()["c"] = 357;
|
||||||
|
sol::optional<int> totally_there = lua["a"]["b"]["c"];
|
||||||
|
REQUIRE(static_cast<bool>(totally_there));
|
||||||
|
REQUIRE(*totally_there == 357);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user