mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Fix optional usages and edge cases. Closes #74
This commit is contained in:
parent
135776d03c
commit
06fecfb4ca
2
Optional
2
Optional
|
@ -1 +1 @@
|
||||||
Subproject commit 9dd28f70f01b4c5417da2f7794fc1ea978bdfd00
|
Subproject commit e62740b328e100ac76821e151cb3cfe7412bd98a
|
|
@ -107,10 +107,11 @@ class basic_table_core : public base_t {
|
||||||
|
|
||||||
template <bool global, typename T, std::size_t I, typename Key>
|
template <bool global, typename T, std::size_t I, typename Key>
|
||||||
decltype(auto) traverse_get_deep_optional( int& popcount, Key&& key ) const {
|
decltype(auto) traverse_get_deep_optional( int& popcount, Key&& key ) const {
|
||||||
|
typedef decltype(stack::get<T>(base_t::lua_state())) R;
|
||||||
auto p = stack::probe_get_field<global>(base_t::lua_state(), std::forward<Key>(key), -1);
|
auto p = stack::probe_get_field<global>(base_t::lua_state(), std::forward<Key>(key), -1);
|
||||||
popcount += p.levels;
|
popcount += p.levels;
|
||||||
if (!p.success)
|
if (!p.success)
|
||||||
return T(nullopt);
|
return R(nullopt);
|
||||||
return stack::get<T>( base_t::lua_state( ) );
|
return stack::get<T>( base_t::lua_state( ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -391,6 +391,9 @@ struct lua_type_of<bool> : std::integral_constant<type, type::boolean> {};
|
||||||
template <>
|
template <>
|
||||||
struct lua_type_of<nil_t> : std::integral_constant<type, type::nil> { };
|
struct lua_type_of<nil_t> : std::integral_constant<type, type::nil> { };
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct lua_type_of<nullopt_t> : std::integral_constant<type, type::nil> { };
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct lua_type_of<sol::error> : std::integral_constant<type, type::string> { };
|
struct lua_type_of<sol::error> : std::integral_constant<type, type::string> { };
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,9 @@ TEST_CASE("functions/deducing-return-order-and-multi-get", "Check if return orde
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("functions/optional-values", "check if optionals can be passed in to be nil or otherwise") {
|
TEST_CASE("functions/optional-values", "check if optionals can be passed in to be nil or otherwise") {
|
||||||
|
struct thing {
|
||||||
|
int v;
|
||||||
|
};
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
lua.script(R"( function f (a)
|
lua.script(R"( function f (a)
|
||||||
return a
|
return a
|
||||||
|
@ -153,9 +156,9 @@ end )");
|
||||||
REQUIRE((bool)testv);
|
REQUIRE((bool)testv);
|
||||||
REQUIRE_FALSE((bool)testn);
|
REQUIRE_FALSE((bool)testn);
|
||||||
REQUIRE(testv.value() == 29);
|
REQUIRE(testv.value() == 29);
|
||||||
int v = lua_bark(sol::optional<int>(29));
|
sol::optional<thing> v = lua_bark(sol::optional<thing>(thing{ 29 }));
|
||||||
REQUIRE_NOTHROW(sol::nil_t n = lua_bark(sol::nullopt));
|
REQUIRE_NOTHROW(sol::nil_t n = lua_bark(sol::nullopt));
|
||||||
REQUIRE(v == 29);
|
REQUIRE(v->v == 29);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("functions/pair-and-tuple-and-proxy-tests", "Check if sol::reference and sol::proxy can be passed to functions as arguments") {
|
TEST_CASE("functions/pair-and-tuple-and-proxy-tests", "Check if sol::reference and sol::proxy can be passed to functions as arguments") {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user