Skip to content

Commit

Permalink
MIGHT AS WELL.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Aug 27, 2016
1 parent 580ebc7 commit 5b5d1e9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
16 changes: 10 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-08-25 16:51:18.743349 UTC
// This header was generated with sol v2.12.1 (revision 354c267)
// Generated 2016-08-27 12:45:21.542724 UTC
// This header was generated with sol v2.12.1 (revision 580ebc7)
// https://github.com/ThePhD/sol2

#ifndef SOL_SINGLE_INCLUDE_HPP
Expand Down Expand Up @@ -10131,6 +10131,8 @@ namespace sol {
typedef std::size_t K;
typedef typename T::value_type V;
typedef typename T::iterator I;
typedef std::remove_reference_t<decltype(*std::declval<I&>())> IR;

struct iter {
T& source;
I it;
Expand Down Expand Up @@ -10175,12 +10177,14 @@ namespace sol {
#endif // Safety
}

static int real_new_index_call_const(std::false_type, lua_State* L) {
luaL_error(L, "sol: cannot write to a const value type");
template <bool b, meta::disable<meta::boolean<b>> = meta::enabler>
static int real_new_index_call_const(std::integral_constant<bool, b>, lua_State* L) {
luaL_error(L, "sol: cannot write to a const value type or an immutable iterator (e.g., std::set)");
return 0;
}

static int real_new_index_call_const(std::true_type, lua_State* L) {
template <bool b, meta::enable<meta::boolean<b>> = meta::enabler>
static int real_new_index_call_const(std::integral_constant<bool, b>, lua_State* L) {
auto& src = get_src(L);
#ifdef SOL_SAFE_USERTYPE
auto maybek = stack::check_get<K>(L, 2);
Expand All @@ -10206,7 +10210,7 @@ namespace sol {
}

static int real_new_index_call(lua_State* L) {
return real_new_index_call_const(meta::neg<std::is_const<V>>(), L);
return real_new_index_call_const(meta::neg<meta::any<std::is_const<V>, std::is_const<IR>>>(), L);
}

static int real_pairs_next_call(lua_State* L) {
Expand Down
12 changes: 8 additions & 4 deletions sol/container_usertype_metatable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ namespace sol {
typedef std::size_t K;
typedef typename T::value_type V;
typedef typename T::iterator I;
typedef std::remove_reference_t<decltype(*std::declval<I&>())> IR;

struct iter {
T& source;
I it;
Expand Down Expand Up @@ -117,12 +119,14 @@ namespace sol {
#endif // Safety
}

static int real_new_index_call_const(std::false_type, lua_State* L) {
luaL_error(L, "sol: cannot write to a const value type");
template <bool b, meta::disable<meta::boolean<b>> = meta::enabler>
static int real_new_index_call_const(std::integral_constant<bool, b>, lua_State* L) {
luaL_error(L, "sol: cannot write to a const value type or an immutable iterator (e.g., std::set)");
return 0;
}

static int real_new_index_call_const(std::true_type, lua_State* L) {
template <bool b, meta::enable<meta::boolean<b>> = meta::enabler>
static int real_new_index_call_const(std::integral_constant<bool, b>, lua_State* L) {
auto& src = get_src(L);
#ifdef SOL_SAFE_USERTYPE
auto maybek = stack::check_get<K>(L, 2);
Expand All @@ -148,7 +152,7 @@ namespace sol {
}

static int real_new_index_call(lua_State* L) {
return real_new_index_call_const(meta::neg<std::is_const<V>>(), L);
return real_new_index_call_const(meta::neg<meta::any<std::is_const<V>, std::is_const<IR>>>(), L);
}

static int real_pairs_next_call(lua_State* L) {
Expand Down
26 changes: 26 additions & 0 deletions test_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>

std::vector<int> test_table_return_one() {
return{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Expand Down Expand Up @@ -89,6 +91,30 @@ TEST_CASE("containers/unordered_map_roundtrip", "make sure unordered_maps can be
REQUIRE(areequal);
}

TEST_CASE("containers/unordered_set_roundtrip", "make sure unordered_sets can be round-tripped") {
sol::state lua;
std::unordered_set<int> v{ 1, 2, 3 };
lua.set_function("f", [&]() -> std::unordered_set<int>& {
return v;
});
lua.script("x = f()");
std::unordered_set<int> x = lua["x"];
bool areequal = x == v;
REQUIRE(areequal);
}

TEST_CASE("containers/set_roundtrip", "make sure sets can be round-tripped") {
sol::state lua;
std::set<int> v{ 1, 2, 3 };
lua.set_function("f", [&]() -> std::set<int>& {
return v;
});
lua.script("x = f()");
std::set<int> x = lua["x"];
bool areequal = x == v;
REQUIRE(areequal);
}

TEST_CASE("containers/custom-usertype", "make sure container usertype metatables can be overridden") {
typedef std::unordered_map<int, int> bark;

Expand Down

0 comments on commit 5b5d1e9

Please sign in to comment.