Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Source/LuaBridge/detail/Invoke.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,28 @@ bool is_handler_valid(const F& f) noexcept
template <class Tuple, std::size_t... Indices>
TypeResult<Tuple> decode_tuple_result(lua_State* L, int first_result_index, std::index_sequence<Indices...>)
{
Tuple value;
auto results = std::make_tuple(
Stack<std::tuple_element_t<Indices, Tuple>>::get(L, first_result_index + static_cast<int>(Indices))...);

std::error_code ec;

const bool ok =
(([&]()
{
using ElementType = std::tuple_element_t<Indices, Tuple>;

auto element = Stack<ElementType>::get(L, first_result_index + static_cast<int>(Indices));
const auto& element = std::get<Indices>(results);
if (! element)
{
ec = element.error();
return false;
}

std::get<Indices>(value) = std::move(*element);
return true;
}())
&& ...);

if (! ok)
return ec;

return value;
return Tuple{ std::move(*std::get<Indices>(results))... };
}

template <class R>
Expand Down
11 changes: 11 additions & 0 deletions Tests/Source/LuaRefTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,17 @@ TEST_F(LuaRefTests, CallReturningTupleSuccess)
EXPECT_EQ("hello", std::get<1>(*r));
}

TEST_F(LuaRefTests, CallReturningTupleWithLuaRef)
{
runLua("result = function() return 1, {2, 'three'} end");
auto r = result().call<std::tuple<int, luabridge::LuaRef>>();
ASSERT_TRUE(r);
EXPECT_EQ(1, std::get<0>(*r));
ASSERT_TRUE(std::get<1>(*r).isTable());
EXPECT_EQ(2, *std::get<1>(*r)[1].cast<int>());
EXPECT_EQ("three", *std::get<1>(*r)[2].cast<std::string>());
}

TEST_F(LuaRefTests, CallReturningTupleWrongType)
{
// Exercises the error path of decodeTupleResult (Invoke.h:58-59):
Expand Down
Loading