Skip to content

Commit

Permalink
Sigh. Make sure that tuple expansion works in buggy VC++ compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Sep 26, 2016
1 parent 63093ec commit d7b037d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
30 changes: 24 additions & 6 deletions single/sol/sol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// This file was generated with a script.
// Generated 2016-09-22 16:13:14.308519 UTC
// This header was generated with sol v2.14.2 (revision dc000fb)
// Generated 2016-09-26 08:01:11.472268 UTC
// This header was generated with sol v2.14.2 (revision 63093ec)
// https://github.com/ThePhD/sol2

#ifndef SOL_SINGLE_INCLUDE_HPP
Expand Down Expand Up @@ -3005,6 +3005,12 @@ namespace sol {
operator int() const { return index; }
};

struct raw_index {
int index;
raw_index(int i) : index(i) {}
operator int() const { return index; }
};

struct absolute_index {
int index;
absolute_index(lua_State* L, int idx) : index(lua_absindex(L, idx)) {}
Expand Down Expand Up @@ -3581,6 +3587,8 @@ namespace sol {
stack_reference() noexcept = default;
stack_reference(nil_t) noexcept : stack_reference() {};
stack_reference(lua_State* L, int i) noexcept : L(L), index(lua_absindex(L, i)) {}
stack_reference(lua_State* L, absolute_index i) noexcept : L(L), index(i) {}
stack_reference(lua_State* L, raw_index i) noexcept : L(L), index(i) {}
stack_reference(stack_reference&& o) noexcept = default;
stack_reference& operator=(stack_reference&&) noexcept = default;
stack_reference(const stack_reference&) noexcept = default;
Expand Down Expand Up @@ -5354,12 +5362,22 @@ namespace sol {

template<typename... Args>
struct getter<std::tuple<Args...>> {
template <std::size_t... I>
static decltype(auto) apply(std::index_sequence<I...>, lua_State* L, int index, record& tracking) {
return std::tuple<decltype(stack::get<Args>(L, index))...>{stack::get<Args>(L, index + tracking.used, tracking)...};
typedef std::tuple<decltype(stack::get<Args>(nullptr, 0))...> R;

template <typename... TArgs>
static R apply(std::index_sequence<>, lua_State*, int, record&, TArgs&&... args) {
// Fuck you too, VC++
return R{std::forward<TArgs>(args)...};
}

template <std::size_t I, std::size_t... Ix, typename... TArgs>
static R apply(std::index_sequence<I, Ix...>, lua_State* L, int index, record& tracking, TArgs&&... args) {
// Fuck you too, VC++
typedef std::tuple_element_t<I, std::tuple<Args...>> T;
return apply(std::index_sequence<Ix...>(), L, index, tracking, std::forward<TArgs>(args)..., stack::get<T>(L, index + tracking.used, tracking));
}

static decltype(auto) get(lua_State* L, int index, record& tracking) {
static R get(lua_State* L, int index, record& tracking) {
return apply(std::make_index_sequence<sizeof...(Args)>(), L, index, tracking);
}
};
Expand Down
22 changes: 16 additions & 6 deletions sol/stack_get.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,22 @@ namespace sol {

template<typename... Args>
struct getter<std::tuple<Args...>> {
template <std::size_t... I>
static decltype(auto) apply(std::index_sequence<I...>, lua_State* L, int index, record& tracking) {
return std::tuple<decltype(stack::get<Args>(L, index))...>{stack::get<Args>(L, index + tracking.used, tracking)...};
}

static decltype(auto) get(lua_State* L, int index, record& tracking) {
typedef std::tuple<decltype(stack::get<Args>(nullptr, 0))...> R;

template <typename... TArgs>
static R apply(std::index_sequence<>, lua_State*, int, record&, TArgs&&... args) {
// Fuck you too, VC++
return R{std::forward<TArgs>(args)...};
}

template <std::size_t I, std::size_t... Ix, typename... TArgs>
static R apply(std::index_sequence<I, Ix...>, lua_State* L, int index, record& tracking, TArgs&&... args) {
// Fuck you too, VC++
typedef std::tuple_element_t<I, std::tuple<Args...>> T;
return apply(std::index_sequence<Ix...>(), L, index, tracking, std::forward<TArgs>(args)..., stack::get<T>(L, index + tracking.used, tracking));
}

static R get(lua_State* L, int index, record& tracking) {
return apply(std::make_index_sequence<sizeof...(Args)>(), L, index, tracking);
}
};
Expand Down
2 changes: 2 additions & 0 deletions sol/stack_reference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace sol {
stack_reference() noexcept = default;
stack_reference(nil_t) noexcept : stack_reference() {};
stack_reference(lua_State* L, int i) noexcept : L(L), index(lua_absindex(L, i)) {}
stack_reference(lua_State* L, absolute_index i) noexcept : L(L), index(i) {}
stack_reference(lua_State* L, raw_index i) noexcept : L(L), index(i) {}
stack_reference(stack_reference&& o) noexcept = default;
stack_reference& operator=(stack_reference&&) noexcept = default;
stack_reference(const stack_reference&) noexcept = default;
Expand Down
6 changes: 6 additions & 0 deletions sol/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ namespace sol {
operator int() const { return index; }
};

struct raw_index {
int index;
raw_index(int i) : index(i) {}
operator int() const { return index; }
};

struct absolute_index {
int index;
absolute_index(lua_State* L, int idx) : index(lua_absindex(L, idx)) {}
Expand Down
11 changes: 11 additions & 0 deletions test_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ struct fer {
}
};

TEST_CASE("functions/tuple-returns", "Make sure tuple returns are ordered properly") {
sol::state lua;
lua.script("function f() return '3', 4 end");

std::tuple<std::string, int> result = lua["f"]();
auto s = std::get<0>(result);
auto v = std::get<1>(result);
REQUIRE(s == "3");
REQUIRE(v == 4);
}

TEST_CASE("functions/overload-resolution", "Check if overloaded function resolution templates compile/work") {
sol::state lua;
lua.open_libraries(sol::lib::base);
Expand Down

0 comments on commit d7b037d

Please sign in to comment.