1 // Copyright (c) 2004 Daniel Wallin and Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
24 #include <luabind/luabind.hpp>
26 struct property_test
: counted_type
<property_test
>
28 property_test(): o(6) {}
35 void set(int a
) { a_
= a
; }
36 int get() const { return a_
; }
38 void set_str(const char* str
)
41 const char* get_str() const
42 { return str_
.c_str(); }
45 COUNTER_GUARD(property_test
);
47 void free_setter(property_test
& p
, int a
)
50 int free_getter(const property_test
& p
)
65 void test_main(lua_State
* L
)
67 using namespace luabind
;
71 class_
<property_test
>("property")
72 .def(luabind::constructor
<>())
73 .def("get", &property_test::get
)
74 .property("a", &property_test::get
, &property_test::set
)
76 "str", &property_test::get_str
, &property_test::set_str
)
77 .def_readonly("o", &property_test::o
)
78 .property("free", &free_getter
, &free_setter
)
79 .def_readwrite("b", &property_test::b
),
83 .property("a", &A::get
),
87 .property("x", &A::get
)
90 DOSTRING(L
, "test = property()\n");
94 "assert(test.a == 5)");
96 DOSTRING(L
, "assert(test.o == 6)");
99 "test.str = 'foobar'\n"
100 "assert(test.str == 'foobar')\n");
104 "assert(test.free == 6)\n");
108 "assert(test.b == 3)\n");
114 "assert(a.a == 5)\n");
117 "assert(a.x == 5)\n");