File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,30 +34,28 @@ bool is_handler_valid(const F& f) noexcept
3434template <class Tuple , std::size_t ... Indices>
3535TypeResult<Tuple> decode_tuple_result (lua_State* L, int first_result_index, std::index_sequence<Indices...>)
3636{
37- Tuple value;
37+ auto results = std::make_tuple (
38+ Stack<std::tuple_element_t <Indices, Tuple>>::get (L, first_result_index + static_cast <int >(Indices))...);
39+
3840 std::error_code ec;
3941
4042 const bool ok =
4143 (([&]()
4244 {
43- using ElementType = std::tuple_element_t <Indices, Tuple>;
44-
45- auto element = Stack<ElementType>::get (L, first_result_index + static_cast <int >(Indices));
45+ const auto & element = std::get<Indices>(results);
4646 if (! element)
4747 {
4848 ec = element.error ();
4949 return false ;
5050 }
51-
52- std::get<Indices>(value) = std::move (*element);
5351 return true ;
5452 }())
5553 && ...);
5654
5755 if (! ok)
5856 return ec;
5957
60- return value ;
58+ return Tuple{ std::move (*std::get<Indices>(results))... } ;
6159}
6260
6361template <class R >
Original file line number Diff line number Diff line change @@ -1187,6 +1187,17 @@ TEST_F(LuaRefTests, CallReturningTupleSuccess)
11871187 EXPECT_EQ (" hello" , std::get<1 >(*r));
11881188}
11891189
1190+ TEST_F (LuaRefTests, CallReturningTupleWithLuaRef)
1191+ {
1192+ runLua (" result = function() return 1, {2, 'three'} end" );
1193+ auto r = result ().call <std::tuple<int , luabridge::LuaRef>>();
1194+ ASSERT_TRUE (r);
1195+ EXPECT_EQ (1 , std::get<0 >(*r));
1196+ ASSERT_TRUE (std::get<1 >(*r).isTable ());
1197+ EXPECT_EQ (2 , *std::get<1 >(*r)[1 ].cast <int >());
1198+ EXPECT_EQ (" three" , *std::get<1 >(*r)[2 ].cast <std::string>());
1199+ }
1200+
11901201TEST_F (LuaRefTests, CallReturningTupleWrongType)
11911202{
11921203 // Exercises the error path of decodeTupleResult (Invoke.h:58-59):
You can’t perform that action at this time.
0 commit comments