summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/sol2/test_containers.cpp
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2016-11-15 22:21:07 -0600
committer cracyc <cracyc@users.noreply.github.com>2016-11-15 22:21:07 -0600
commita68d4239929802bca7131d4b97c2b8d149fbbcb9 (patch)
tree03a497191ccd83206e94c60aca635eb44d51c0f7 /3rdparty/sol2/test_containers.cpp
parent4d533249fdf28d3a473426130a82e673b1b1d5ec (diff)
luaengine: use initializers (nw)
Diffstat (limited to '3rdparty/sol2/test_containers.cpp')
-rw-r--r--3rdparty/sol2/test_containers.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/3rdparty/sol2/test_containers.cpp b/3rdparty/sol2/test_containers.cpp
index 1ed07e24a9f..acb3581440b 100644
--- a/3rdparty/sol2/test_containers.cpp
+++ b/3rdparty/sol2/test_containers.cpp
@@ -423,3 +423,38 @@ TEST_CASE("containers/is-container", "make sure the is_container trait behaves p
}
REQUIRE(options::livingcount == 0);
}
+
+TEST_CASE("containers/readonly", "make sure readonly members are stored appropriately") {
+ sol::state lua;
+ lua.open_libraries();
+
+ struct bar {
+ int x = 24;
+ };
+
+ struct foo {
+ std::list<bar> seq;
+ };
+
+ lua.new_usertype<foo>(
+ "foo",
+ "seq", &foo::seq, // this one works
+ "readonly_seq", sol::readonly(&foo::seq) // this one does not work
+ );
+ lua["value"] = std::list<bar>{ {},{},{} };
+
+ lua.script(R"(
+a = foo.new()
+x = a.seq
+a.seq = value
+y = a.readonly_seq
+)");
+ std::list<bar>& seqrefx = lua["x"];
+ std::list<bar>& seqrefy = lua["y"];
+ REQUIRE(&seqrefx == &seqrefy);
+ REQUIRE(seqrefx.size() == 3);
+ auto result = lua.do_string(R"(
+a.readonly_seq = value;
+)");
+ REQUIRE_FALSE(result.valid());
+}