Fix optional usages and edge cases. Closes #74

This commit is contained in:
ThePhD 2016-05-02 01:52:51 -04:00
parent 135776d03c
commit 06fecfb4ca
4 changed files with 11 additions and 4 deletions

@ -1 +1 @@
Subproject commit 9dd28f70f01b4c5417da2f7794fc1ea978bdfd00
Subproject commit e62740b328e100ac76821e151cb3cfe7412bd98a

View File

@ -107,10 +107,11 @@ class basic_table_core : public base_t {
template <bool global, typename T, std::size_t I, typename Key>
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);
popcount += p.levels;
if (!p.success)
return T(nullopt);
return R(nullopt);
return stack::get<T>( base_t::lua_state( ) );
}

View File

@ -391,6 +391,9 @@ struct lua_type_of<bool> : std::integral_constant<type, type::boolean> {};
template <>
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 <>
struct lua_type_of<sol::error> : std::integral_constant<type, type::string> { };

View File

@ -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") {
struct thing {
int v;
};
sol::state lua;
lua.script(R"( function f (a)
return a
@ -153,9 +156,9 @@ end )");
REQUIRE((bool)testv);
REQUIRE_FALSE((bool)testn);
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(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") {