MIGHT AS WELL.

This commit is contained in:
ThePhD 2016-08-27 08:45:37 -04:00
parent 580ebc700f
commit 5b5d1e9ca6
3 changed files with 44 additions and 10 deletions

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2016-08-25 16:51:18.743349 UTC // Generated 2016-08-27 12:45:21.542724 UTC
// This header was generated with sol v2.12.1 (revision 354c267) // This header was generated with sol v2.12.1 (revision 580ebc7)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP #ifndef SOL_SINGLE_INCLUDE_HPP
@ -10131,6 +10131,8 @@ namespace sol {
typedef std::size_t K; typedef std::size_t K;
typedef typename T::value_type V; typedef typename T::value_type V;
typedef typename T::iterator I; typedef typename T::iterator I;
typedef std::remove_reference_t<decltype(*std::declval<I&>())> IR;
struct iter { struct iter {
T& source; T& source;
I it; I it;
@ -10175,12 +10177,14 @@ namespace sol {
#endif // Safety #endif // Safety
} }
static int real_new_index_call_const(std::false_type, lua_State* L) { template <bool b, meta::disable<meta::boolean<b>> = meta::enabler>
luaL_error(L, "sol: cannot write to a const value type"); 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; 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); auto& src = get_src(L);
#ifdef SOL_SAFE_USERTYPE #ifdef SOL_SAFE_USERTYPE
auto maybek = stack::check_get<K>(L, 2); auto maybek = stack::check_get<K>(L, 2);
@ -10206,7 +10210,7 @@ namespace sol {
} }
static int real_new_index_call(lua_State* L) { 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) { static int real_pairs_next_call(lua_State* L) {

View File

@ -73,6 +73,8 @@ namespace sol {
typedef std::size_t K; typedef std::size_t K;
typedef typename T::value_type V; typedef typename T::value_type V;
typedef typename T::iterator I; typedef typename T::iterator I;
typedef std::remove_reference_t<decltype(*std::declval<I&>())> IR;
struct iter { struct iter {
T& source; T& source;
I it; I it;
@ -117,12 +119,14 @@ namespace sol {
#endif // Safety #endif // Safety
} }
static int real_new_index_call_const(std::false_type, lua_State* L) { template <bool b, meta::disable<meta::boolean<b>> = meta::enabler>
luaL_error(L, "sol: cannot write to a const value type"); 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; 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); auto& src = get_src(L);
#ifdef SOL_SAFE_USERTYPE #ifdef SOL_SAFE_USERTYPE
auto maybek = stack::check_get<K>(L, 2); auto maybek = stack::check_get<K>(L, 2);
@ -148,7 +152,7 @@ namespace sol {
} }
static int real_new_index_call(lua_State* L) { 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) { static int real_pairs_next_call(lua_State* L) {

View File

@ -8,6 +8,8 @@
#include <list> #include <list>
#include <map> #include <map>
#include <unordered_map> #include <unordered_map>
#include <set>
#include <unordered_set>
std::vector<int> test_table_return_one() { std::vector<int> test_table_return_one() {
return{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; return{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
@ -89,6 +91,30 @@ TEST_CASE("containers/unordered_map_roundtrip", "make sure unordered_maps can be
REQUIRE(areequal); 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") { TEST_CASE("containers/custom-usertype", "make sure container usertype metatables can be overridden") {
typedef std::unordered_map<int, int> bark; typedef std::unordered_map<int, int> bark;