Make shared_ptr_converter public.
[luabind.git] / test / test_properties.cpp
blobac5cbb04abf581a165fcd0692939019c1b909620
1 // Copyright Daniel Wallin 2008. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 // This test expands on test_attributes.cpp, testing the new property
6 // implementation features.
8 #include "test.hpp"
9 #include <luabind/luabind.hpp>
11 struct Base
12 {};
14 void test_main(lua_State* L)
16 using namespace luabind;
18 module(L) [
19 class_<Base>("Base")
20 .def(constructor<>())
23 DOSTRING(L,
24 "class 'Readonly' (Base)\n"
25 " function Readonly:__init(x)\n"
26 " Base.__init(self)\n"
27 " self._x = x\n"
28 " end\n"
30 " function Readonly:getX()\n"
31 " return self._x\n"
32 " end\n"
34 " Readonly.x = property(Readonly.getX)\n"
37 DOSTRING(L,
38 "class 'Readwrite' (Readonly)\n"
39 " function Readwrite:__init(x)\n"
40 " Readonly.__init(self, x)\n"
41 " end\n"
43 " function Readwrite:setX(x)\n"
44 " self._x = x\n"
45 " end\n"
47 " Readwrite.x = property(Readonly.getX, Readwrite.setX)\n"
50 DOSTRING(L,
51 "r = Readonly(1)\n"
52 "assert(r.x == 1)\n"
55 DOSTRING_EXPECTED(L,
56 "r = Readonly(1)\n"
57 "r.x = 2\n"
58 , "property 'x' is read only"
61 DOSTRING(L,
62 "r = Readwrite(2)\n"
63 "assert(r.x == 2)\n"
64 "r.x = 3\n"
65 "assert(r.x == 3)\n"
66 "assert(r._x == 3)\n"
69 DOSTRING(L,
70 "r = Readonly(1)\n"
71 "r.y = 2\n"
72 "assert(r.y == 2)\n"