From a68d4239929802bca7131d4b97c2b8d149fbbcb9 Mon Sep 17 00:00:00 2001 From: cracyc Date: Tue, 15 Nov 2016 22:21:07 -0600 Subject: luaengine: use initializers (nw) --- 3rdparty/sol2/test_containers.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to '3rdparty/sol2/test_containers.cpp') 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 seq; + }; + + lua.new_usertype( + "foo", + "seq", &foo::seq, // this one works + "readonly_seq", sol::readonly(&foo::seq) // this one does not work + ); + lua["value"] = std::list{ {},{},{} }; + + lua.script(R"( +a = foo.new() +x = a.seq +a.seq = value +y = a.readonly_seq +)"); + std::list& seqrefx = lua["x"]; + std::list& seqrefy = lua["y"]; + REQUIRE(&seqrefx == &seqrefy); + REQUIRE(seqrefx.size() == 3); + auto result = lua.do_string(R"( +a.readonly_seq = value; +)"); + REQUIRE_FALSE(result.valid()); +} -- cgit v1.2.3-70-g09d2